/[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 274 - (hide annotations) (download) (as text)
Sat Oct 9 00:46:18 2004 UTC (19 years, 5 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 9080 byte(s)
* MidiInputPort: fixed dispatching of MIDI events to engines which are
  listening to all MIDI channels
* switched MIDI channel indexing to low level indexing (means 0..15 now)

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

  ViewVC Help
Powered by ViewVC