/[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 2140 - (hide annotations) (download)
Tue Oct 5 10:35:13 2010 UTC (13 years, 5 months ago) by schoenebeck
File size: 8229 byte(s)
* raised limit of program change queue from 100 to 512
  (as suggested by Alex Stone)
* removed limit of maximum amount of MIDI ports per MIDI device, since
  there is no reason for this limit
* minor syntax simplification regarding 2 new LSCP commands: changed
  "SET FX_SEND SEND_EFFECT"" to "SET FX_SEND EFFECT" and changed
  "REMOVE FX_SEND SEND_EFFECT"" to "REMOVE FX_SEND EFFECT", also changed
  the respective category field of command "GET FX_SEND INFO" from
  "SEND_EFFECT" to "EFFECT"
* updated LSCP specification document
* bumped version to 1.0.0.cvs10

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

  ViewVC Help
Powered by ViewVC