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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 551 - (hide annotations) (download) (as text)
Tue May 17 18:16:54 2005 UTC (19 years ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8560 byte(s)
* Implemented MIDI program change as general, engine independant solution.
  The program number will determine the sampler channel to which the MIDI
  device will be connected to and the given MIDI channel defines on which
  MIDI channel that sampler channel should listen to. Also the program
  change will disconnect probably established connection from the previous
  program change event.

1 schoenebeck 201 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 551 * Copyright (C) 2005 Christian Schoenebeck *
7 schoenebeck 201 * *
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_MIDIINPUTDEVICE_H__
25     #define __LS_MIDIINPUTDEVICE_H__
26    
27     #include <stdexcept>
28     #include <set>
29     #include <map>
30     #include <vector>
31    
32     #include "../../common/global.h"
33     #include "../../common/LinuxSamplerException.h"
34     #include "../DeviceParameter.h"
35 schoenebeck 221 #include "MidiInputPort.h"
36 schoenebeck 201 #include "../../engines/common/Engine.h"
37    
38     namespace LinuxSampler {
39    
40     // just symbol prototyping
41 schoenebeck 221 class MidiInputPort;
42 schoenebeck 201 class Engine;
43    
44 schoenebeck 221 /**
45     * Midi input exception that should be thrown by the MidiInputDevice
46     * descendants in case initialization of the MIDI input system failed
47     * (which should be done in the constructor of the MidiInputDevice
48     * descendant).
49     */
50     class MidiInputException : public LinuxSamplerException {
51     public:
52     MidiInputException(const std::string& msg) : LinuxSamplerException(msg) {}
53     };
54    
55 schoenebeck 201 /** Abstract base class for MIDI input drivers in LinuxSampler
56     *
57     * This class will be derived by specialized classes which implement the
58     * connection to a specific MIDI input system (e.g. Alsa Sequencer,
59     * CoreMIDI). The MidiInputDevice desendant should just call the
60     * appropriate (protected) Dispatch* method here when an MIDI event
61     * occured. The dispatch* methods here will automatically forward the
62     * MIDI event to the appropriate, connected sampler engines.
63     */
64 schoenebeck 207 class MidiInputDevice : public Device {
65 schoenebeck 201 public:
66    
67     /////////////////////////////////////////////////////////////////
68     // type definitions
69    
70 schoenebeck 221 /** Device Parameter 'ACTIVE'
71     *
72     * Used to activate / deactivate the MIDI input device.
73     */
74 schoenebeck 201 class ParameterActive : public DeviceCreationParameterBool {
75 schoenebeck 221 public:
76     ParameterActive();
77     ParameterActive(String active);
78     virtual String Description();
79     virtual bool Fix();
80     virtual bool Mandatory();
81     virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
82     virtual optional<bool> DefaultAsBool(std::map<String,String> Parameters);
83     virtual void OnSetValue(bool b) throw (LinuxSamplerException);
84     static String Name();
85     };
86 schoenebeck 201
87 schoenebeck 221 /** Device Parameter 'PORTS'
88     *
89     * Used to increase / decrease the number of MIDI ports of the
90     * MIDI input device.
91     */
92     class ParameterPorts : public DeviceCreationParameterInt {
93     public:
94     ParameterPorts();
95     ParameterPorts(String val);
96     virtual String Description();
97     virtual bool Fix();
98     virtual bool Mandatory();
99     virtual std::map<String,DeviceCreationParameter*> DependsAsParameters();
100     virtual optional<int> DefaultAsInt(std::map<String,String> Parameters);
101     virtual optional<int> RangeMinAsInt(std::map<String,String> Parameters);
102     virtual optional<int> RangeMaxAsInt(std::map<String,String> Parameters);
103     virtual std::vector<int> PossibilitiesAsInt(std::map<String,String> Parameters);
104     virtual void OnSetValue(int i) throw (LinuxSamplerException);
105     static String Name();
106     };
107 schoenebeck 201
108    
109    
110 schoenebeck 221 /////////////////////////////////////////////////////////////////
111     // abstract methods
112     // (these have to be implemented by the descendant)
113 schoenebeck 201
114 schoenebeck 221 /**
115     * Start listen to MIDI input events on the MIDI input port.
116     * The MIDIInputPort descendant should forward all MIDI input
117     * events by calling the appropriate (protected) Dispatch*
118     * method of class MidiInputPort.
119     */
120     virtual void Listen() = 0;
121 schoenebeck 201
122 schoenebeck 221 /**
123     * Stop to listen to MIDI input events on the MIDI input port.
124     * After this method was called, the MidiInputPort descendant
125     * should ignore all MIDI input events.
126     */
127     virtual void StopListen() = 0;
128 schoenebeck 201
129 schoenebeck 221 /**
130     * Return device driver name
131     */
132     virtual String Driver() = 0;
133 schoenebeck 201
134 schoenebeck 221 /**
135     * Create new Midi port
136     * This will be called by AcquirePorts
137     * Each individual device must implement this.
138     */
139     virtual MidiInputPort* CreateMidiPort() = 0;
140 schoenebeck 201
141    
142    
143 schoenebeck 221 /////////////////////////////////////////////////////////////////
144     // normal methods
145     // (usually not to be overriden by descendant)
146 schoenebeck 201
147 schoenebeck 221 /**
148     * Return midi port \a iPort.
149     *
150     * @throws MidiInputException if index out of bounds
151     */
152     MidiInputPort* GetPort(uint iPort) throw (MidiInputException);
153 schoenebeck 201
154 schoenebeck 221 /**
155     * Return all device parameter settings.
156     */
157     std::map<String,DeviceCreationParameter*> DeviceParameters();
158 schoenebeck 201
159     protected:
160 schoenebeck 221 std::map<String,DeviceCreationParameter*> Parameters; ///< All device parameters.
161 schoenebeck 551 std::map<int,MidiInputPort*> Ports; ///< All MIDI ports.
162     void* pSampler; ///< Sampler instance. FIXME: should actually be of type Sampler*
163 schoenebeck 201
164 schoenebeck 221 /**
165     * Constructor
166 schoenebeck 551 *
167     * FIXME: the pointer argument \a pSapmler should actually be of type Sampler*.
168     * Unfortunately the bidirectional relationship between this
169     * header and Sampler.h would clash on header file inclusion,
170     * so that's why I had to make it of type void* here. This is
171     * an annoying constraint of C++.
172 schoenebeck 221 */
173 schoenebeck 551 MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters, void* pSampler);
174 schoenebeck 201
175 schoenebeck 221 /**
176     * Destructor
177     */
178     virtual ~MidiInputDevice();
179 schoenebeck 201
180     /**
181     * Set number of MIDI ports required by the engine
182 schoenebeck 221 * This can either do nothing, create more ports
183     * or destroy ports depenging on the parameter
184     * and how many ports already exist on this driver.
185 schoenebeck 201 *
186     * @param Ports - number of ports to be left on this driver after this call.
187     */
188 schoenebeck 221 void AcquirePorts(uint Ports);
189 schoenebeck 201
190 schoenebeck 277 friend class ParameterActive;
191     friend class ParameterPorts;
192 schoenebeck 221 friend class Sampler; // allow Sampler class to destroy midi devices
193 schoenebeck 551 friend class MidiInputPort; // allow MidiInputPort to access pSampler
194 schoenebeck 201 };
195     }
196    
197     #endif // __LS_MIDIINPUTDEVICE_H__

  ViewVC Help
Powered by ViewVC