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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1305 - (hide annotations) (download)
Mon Aug 27 07:51:28 2007 UTC (16 years, 7 months ago) by iliev
File size: 6754 byte(s)
* added default min and max values to restrict the number of allowed
  audio output channels and MIDI input ports
* the connection to the PCM interface is now closed when destroying
  an audio output device

1 schoenebeck 201 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 880 * Copyright (C) 2005, 2006 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     #include "MidiInputDevice.h"
25    
26 iliev 1295 #include "../../Sampler.h"
27    
28 schoenebeck 201 namespace LinuxSampler {
29    
30 schoenebeck 221 // *************** ParameterActive ***************
31     // *
32    
33     MidiInputDevice::ParameterActive::ParameterActive() : DeviceCreationParameterBool() {
34     InitWithDefault();
35 schoenebeck 201 }
36    
37 schoenebeck 221 MidiInputDevice::ParameterActive::ParameterActive(String active) : DeviceCreationParameterBool(active) {
38 schoenebeck 201 }
39    
40 schoenebeck 221 String MidiInputDevice::ParameterActive::Description() {
41     return "Enable / disable device";
42 schoenebeck 201 }
43    
44 schoenebeck 221 bool MidiInputDevice::ParameterActive::Fix() {
45     return false;
46 schoenebeck 201 }
47    
48 schoenebeck 221 bool MidiInputDevice::ParameterActive::Mandatory() {
49     return false;
50 schoenebeck 201 }
51    
52 schoenebeck 221 std::map<String,DeviceCreationParameter*> MidiInputDevice::ParameterActive::DependsAsParameters() {
53     return std::map<String,DeviceCreationParameter*>();
54 schoenebeck 201 }
55    
56 schoenebeck 221 optional<bool> MidiInputDevice::ParameterActive::DefaultAsBool(std::map<String,String> Parameters) {
57     return true;
58 schoenebeck 201 }
59    
60 schoenebeck 880 void MidiInputDevice::ParameterActive::OnSetValue(bool b) throw (Exception) {
61 schoenebeck 221 if (b) ((MidiInputDevice*)pDevice)->Listen();
62     else ((MidiInputDevice*)pDevice)->StopListen();
63 schoenebeck 201 }
64    
65 schoenebeck 221 String MidiInputDevice::ParameterActive::Name() {
66     return "ACTIVE";
67 schoenebeck 201 }
68    
69 schoenebeck 221
70    
71     // *************** ParameterPorts ***************
72     // *
73    
74     MidiInputDevice::ParameterPorts::ParameterPorts() : DeviceCreationParameterInt() {
75     InitWithDefault();
76 schoenebeck 201 }
77    
78 schoenebeck 221 MidiInputDevice::ParameterPorts::ParameterPorts(String val) : DeviceCreationParameterInt(val) {
79 schoenebeck 201 }
80    
81 schoenebeck 221 String MidiInputDevice::ParameterPorts::Description() {
82     return "Number of ports";
83 schoenebeck 201 }
84    
85 schoenebeck 221 bool MidiInputDevice::ParameterPorts::Fix() {
86     return false;
87 schoenebeck 201 }
88    
89 schoenebeck 221 bool MidiInputDevice::ParameterPorts::Mandatory() {
90     return false;
91 schoenebeck 201 }
92    
93 schoenebeck 221 std::map<String,DeviceCreationParameter*> MidiInputDevice::ParameterPorts::DependsAsParameters() {
94     return std::map<String,DeviceCreationParameter*>();
95     }
96    
97     optional<int> MidiInputDevice::ParameterPorts::DefaultAsInt(std::map<String,String> Parameters) {
98 schoenebeck 226 return 1;
99 schoenebeck 221 }
100    
101     optional<int> MidiInputDevice::ParameterPorts::RangeMinAsInt(std::map<String,String> Parameters) {
102 iliev 1305 return 1;
103 schoenebeck 221 }
104    
105     optional<int> MidiInputDevice::ParameterPorts::RangeMaxAsInt(std::map<String,String> Parameters) {
106 iliev 1305 return 100;
107 schoenebeck 221 }
108    
109     std::vector<int> MidiInputDevice::ParameterPorts::PossibilitiesAsInt(std::map<String,String> Parameters) {
110     return std::vector<int>();
111     }
112    
113 schoenebeck 880 void MidiInputDevice::ParameterPorts::OnSetValue(int i) throw (Exception) {
114 iliev 1295 MidiInputDevice* dev = static_cast<MidiInputDevice*> (pDevice);
115     Sampler* s = static_cast<Sampler*> (dev->pSampler);
116     std::map<uint, SamplerChannel*> channels = s->GetSamplerChannels();
117     std::map<uint, SamplerChannel*>::iterator iter = channels.begin();
118     for (; iter != channels.end(); iter++) {
119     SamplerChannel* chn = iter->second;
120     if (chn->GetMidiInputDevice() == NULL || chn->GetMidiInputDevice() != pDevice) {
121     continue;
122     }
123    
124     int port = chn->GetMidiInputPort();
125     if (port >= i) {
126     String err = "Sampler channel " + ToString(iter->first);
127     err += " is still connected to MIDI port " + ToString(port);
128     throw Exception(err);
129     }
130     }
131    
132 schoenebeck 221 ((MidiInputDevice*)pDevice)->AcquirePorts(i);
133     }
134    
135     String MidiInputDevice::ParameterPorts::Name() {
136     return "PORTS";
137     }
138    
139    
140    
141     // *************** MidiInputDevice ***************
142     // *
143    
144 schoenebeck 551 MidiInputDevice::MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters, void* pSampler) {
145     this->Parameters = DriverParameters;
146     this->pSampler = pSampler;
147 schoenebeck 221 }
148    
149     MidiInputDevice::~MidiInputDevice() {
150 persson 835 std::map<String,DeviceCreationParameter*>::iterator iter = Parameters.begin();
151     while (iter != Parameters.end()) {
152     delete iter->second;
153     iter++;
154     }
155     Parameters.clear();
156 schoenebeck 221 }
157    
158     MidiInputPort* MidiInputDevice::GetPort(uint iPort) throw (MidiInputException) {
159     if (iPort >= Ports.size()) throw MidiInputException("There is no port " + ToString(iPort));
160     return Ports[iPort];
161     }
162    
163     std::map<String,DeviceCreationParameter*> MidiInputDevice::DeviceParameters() {
164     return Parameters;
165     }
166    
167 schoenebeck 201 void MidiInputDevice::AcquirePorts(uint newPorts) {
168     int diff = this->Ports.size() - newPorts;
169     if (!diff)
170     return; //Number of ports matches already, nothing to do.
171    
172     while (diff != 0) {
173     if (diff > 0) { //We've got too many ports, remove one
174     std::map<int,MidiInputPort*>::iterator portsIter = Ports.end();
175     --portsIter;
176 persson 836 delete portsIter->second;
177 schoenebeck 201 Ports.erase(portsIter);
178     diff--;
179     }
180     if (diff < 0) { //We don't have enough ports, create one
181     MidiInputPort* midiPort = this->CreateMidiPort();
182     Ports[midiPort->portNumber] = midiPort;
183     diff++;
184     }
185     }
186     }
187    
188     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC