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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1694 by schoenebeck, Sun Oct 14 22:00:17 2007 UTC revision 1695 by schoenebeck, Sat Feb 16 01:09:33 2008 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2008 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 121  namespace LinuxSampler { Line 121  namespace LinuxSampler {
121              if (chn->GetMidiInputDevice() == NULL || chn->GetMidiInputDevice() != pDevice) {              if (chn->GetMidiInputDevice() == NULL || chn->GetMidiInputDevice() != pDevice) {
122                  continue;                  continue;
123              }              }
124                
125              int port = chn->GetMidiInputPort();              int port = chn->GetMidiInputPort();
126              if (port >= i) {              if (port >= i) {
127                  String err = "Sampler channel " + ToString(iter->first);                  String err = "Sampler channel " + ToString(iter->first);
# Line 129  namespace LinuxSampler { Line 129  namespace LinuxSampler {
129                  throw Exception(err);                  throw Exception(err);
130              }              }
131          }          }
132            
133          ((MidiInputDevice*)pDevice)->AcquirePorts(i);          ((MidiInputDevice*)pDevice)->AcquirePorts(i);
134      }      }
135    
# Line 161  namespace LinuxSampler { Line 161  namespace LinuxSampler {
161          return Ports[iPort];          return Ports[iPort];
162      }      }
163    
164        uint MidiInputDevice::PortCount() {
165            return Ports.size();
166        }
167    
168      std::map<String,DeviceCreationParameter*> MidiInputDevice::DeviceParameters() {      std::map<String,DeviceCreationParameter*> MidiInputDevice::DeviceParameters() {
169              return Parameters;          return Parameters;
170        }
171    
172        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      void MidiInputDevice::AcquirePorts(uint newPorts) {      void MidiInputDevice::AcquirePorts(uint newPorts) {
199           int diff = this->Ports.size() - newPorts;          //FIXME: hooo, this looks scary, no synchronization AT ALL yet!
200           if (!diff)          int diff = this->Ports.size() - newPorts;
201                   return; //Number of ports matches already, nothing to do.          if (!diff)
202                return; // number of ports matches already, nothing to do
203           while (diff != 0) {  
204                   if (diff > 0) {        //We've got too many ports, remove one          while (diff != 0) {
205                           std::map<int,MidiInputPort*>::iterator portsIter = Ports.end();              if (diff > 0) { // we've got too many ports, remove one
206                           --portsIter;                  std::map<int,MidiInputPort*>::iterator portsIter = Ports.end();
207                           delete portsIter->second;                  --portsIter;
208                           Ports.erase(portsIter);  
209                           diff--;                  fireMidiPortToBeRemoved(portsIter->second);
210                   }                  delete portsIter->second;
211                   if (diff < 0) {       //We don't have enough ports, create one                  Ports.erase(portsIter);
212                           MidiInputPort* midiPort = this->CreateMidiPort();                  diff--;
213                           Ports[midiPort->portNumber] = midiPort;              }
214                           diff++;              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      }      }
223    
224  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.1694  
changed lines
  Added in v.1695

  ViewVC Help
Powered by ViewVC