/[svn]/linuxsampler/trunk/src/drivers/midi/MidiInputPort.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/drivers/midi/MidiInputPort.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 840 - (hide annotations) (download) (as text)
Sun Feb 26 13:00:08 2006 UTC (18 years, 2 months ago) by persson
File MIME type: text/x-c++hdr
File size: 10297 byte(s)
* fixed some concurrency problems between the lscp thread and the
  audio/midi threads for these commands: load engine, set channel
  audio output device, set channel midi input device/port/channel and
  remove channel. Thanks to Vincent Bongiorno for bug reports and
  testing.
* removed an autotools warning
* fixed an iterator bug
* minor code clean-ups

1 schoenebeck 221 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 411 * Copyright (C) 2005 Christian Schoenebeck *
7 schoenebeck 221 * *
8     * This program is free software; you can redistribute it and/or modify *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #ifndef __LS_MIDIINPUTPORT_H__
25     #define __LS_MIDIINPUTPORT_H__
26    
27     #include "../../common/global.h"
28 schoenebeck 551 #include "../../common/Mutex.h"
29 schoenebeck 221 #include "../../common/LinuxSamplerException.h"
30     #include "../DeviceParameter.h"
31 schoenebeck 675 #include "midi.h"
32 schoenebeck 221 #include "MidiInputDevice.h"
33 schoenebeck 411 #include "../../engines/common/EngineChannel.h"
34 persson 840 #include "../../common/SynchronizedConfig.h"
35 schoenebeck 221
36     namespace LinuxSampler {
37    
38     // just symbol prototyping
39     class MidiInputDevice;
40 schoenebeck 675 class EngineChannel;
41 schoenebeck 221
42     class MidiInputPort {
43     public:
44    
45     /////////////////////////////////////////////////////////////////
46     // type definitions
47    
48     /** MIDI Port Parameter 'NAME'
49     *
50     * Used to assign an arbitrary name to the MIDI port.
51     */
52     class ParameterName : public DeviceRuntimeParameterString {
53     public:
54     ParameterName(MidiInputPort* pPort);
55     ParameterName(MidiInputPort* pPort, String val);
56     virtual String Description();
57     virtual bool Fix();
58     virtual std::vector<String> PossibilitiesAsString();
59     virtual void OnSetValue(String s) throw (LinuxSamplerException);
60     protected:
61     MidiInputPort* pPort;
62     };
63    
64    
65    
66     /////////////////////////////////////////////////////////////////
67     // normal methods
68     // (usually not to be overriden by descendant)
69    
70     /**
71     * Connect given sampler engine with this MIDI input device.
72     * The engine can either be connected to one specific MIDI
73     * channel or all MIDI channels. If an engine gets connected
74     * twice to this MIDI input device, then the engine's old
75     * connection will be detached (no matter on which MIDI channel).
76     *
77     * @param pEngine - sampler engine
78     * @param MidiChannel - MIDI channel to connect to
79     * @throws MidiInputException if MidiChannel argument invalid
80     */
81 schoenebeck 411 void Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel);
82 schoenebeck 221
83     /**
84     * Disconnect given sampler engine from this MIDI input device.
85 schoenebeck 551 * If the given engine was not connected with this device,
86     * nothing happens.
87 schoenebeck 221 *
88     * @param pEngine - sampler engine
89     */
90 schoenebeck 411 void Disconnect(EngineChannel* pEngineChannel);
91 schoenebeck 221
92     /**
93     * Return MIDI device where this MIDI port belongs to.
94     */
95     MidiInputDevice* GetDevice();
96    
97     /**
98     * Return port number with which this MIDI port is registered to
99     * the MIDI device.
100     */
101     uint GetPortNumber();
102    
103     /**
104     * Return all parameter settings of this MIDI port.
105     */
106     std::map<String,DeviceRuntimeParameter*> PortParameters();
107    
108    
109    
110    
111    
112     /////////////////////////////////////////////////////////////////
113     // dispatch methods
114     // (should be called by the MidiInputDevice descendant on events)
115    
116     /**
117     * Should be called by the implementing MIDI input device
118     * whenever a note on event arrived, this will cause the note on
119     * event to be forwarded to all connected engines on the
120     * corresponding MIDI channel.
121     *
122     * @param Key - MIDI key number of the triggered key
123     * @param Velocity - MIDI velocity of the triggered key
124     * @param MidiChannel - MIDI channel on which event occured on
125 schoenebeck 274 * (low level indexing, means 0..15)
126 schoenebeck 221 */
127     void DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel);
128    
129     /**
130     * Should be called by the implementing MIDI input device
131     * whenever a note off event arrived, this will cause the note
132     * off event to be forwarded to all connected engines on the
133     * corresponding MIDI channel.
134     *
135     * @param Key - MIDI key number of the released key
136     * @param Velocity - MIDI velocity of the released key
137     * @param MidiChannel - MIDI channel on which event occured on
138 schoenebeck 274 * (low level indexing, means 0..15)
139 schoenebeck 221 */
140     void DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel);
141    
142     /**
143     * Should be called by the implementing MIDI input device
144     * whenever a pitchbend event arrived, this will cause the
145     * pitchbend event to be forwarded to all connected engines.
146     *
147     * @param Pitch - MIDI pitch value
148     * @param MidiChannel - MIDI channel on which event occured on
149 schoenebeck 274 * (low level indexing, means 0..15)
150 schoenebeck 221 */
151     void DispatchPitchbend(int Pitch, uint MidiChannel);
152    
153     /**
154     * Should be called by the implementing MIDI input device
155     * whenever a control change event arrived, this will cause the
156     * control change event to be forwarded to all engines on the
157     * corresponding MIDI channel.
158     *
159     * @param Controller - MIDI controller number
160     * @param Value - MIDI control change value
161     * @param MidiChannel - MIDI channel on which event occured on
162 schoenebeck 274 * (low level indexing, means 0..15)
163 schoenebeck 221 */
164     void DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel);
165    
166 schoenebeck 244 /**
167     * Should be called by the implementing MIDI input device
168 schoenebeck 551 * whenever a program change event arrived, this will cause the
169     * appropriate sampler channel to be connected with this MIDI
170     * device.
171     *
172     * For example consider a program change event on MIDI channel
173     * 3 for program number 18. This would cause this MIDI input
174     * device to be connected to sampler channel 18 and would cause
175     * sampler channel 18 to listen to MIDI channel 3.
176     *
177     * This is the current, general implementation of program
178     * change events. It might change in future, e.g to allow
179     * sampler engines to allow by themselfes how to act on a
180     * program change event.
181     *
182     * @param Program - sampler channel to connect to this MIDI
183     * input device
184     * @param MidiChannel - MIDI channel on which sampler channel
185     * \a Program should listen to
186     */
187     void DispatchProgramChange(uint8_t Program, uint MidiChannel);
188    
189     /**
190     * Should be called by the implementing MIDI input device
191 schoenebeck 244 * whenever a system exclusive message arrived, this will cause
192     * the message to be forwarded to all connected engines.
193     *
194     * @param pData - pointer to the sysex data
195     * @param Size - length of the sysex data (in bytes)
196     */
197     void DispatchSysex(void* pData, uint Size);
198    
199 schoenebeck 221 protected:
200     MidiInputDevice* pDevice;
201     int portNumber;
202     std::map<String,DeviceRuntimeParameter*> Parameters; ///< All port parameters.
203 persson 840 typedef std::set<EngineChannel*> MidiChannelMap_t[17];
204     SynchronizedConfig<MidiChannelMap_t> MidiChannelMap; ///< Contains the list of connected engines for each MIDI channel, where index 0 points to the list of engines which are connected to all MIDI channels. Usually it's not necessary for the descendant to use this map, instead it should just use the Dispatch* methods.
205 schoenebeck 551 Mutex MidiChannelMapMutex; ///< Used to protect the MidiChannelMap from being used at the same time by different threads.
206 schoenebeck 221
207     /**
208     * Constructor
209     */
210     MidiInputPort(MidiInputDevice* pDevice, int portNumber);
211    
212     /**
213     * Destructor
214     */
215     virtual ~MidiInputPort();
216    
217     friend class MidiInputDevice;
218 schoenebeck 675
219 schoenebeck 551 private:
220     EngineChannel* pPreviousProgramChangeEngineChannel; ///< Points to the engine channel which was connected by the previous DispatchProgramChange() call.
221 schoenebeck 221 };
222    
223     } // namsepace LinuxSampler
224    
225     #endif // __LS_MIDIINPUTPORT_H__

  ViewVC Help
Powered by ViewVC