/[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 836 - (hide annotations) (download)
Wed Feb 8 20:28:46 2006 UTC (18 years, 2 months ago) by persson
File size: 5966 byte(s)
* fixed some invalid iterator errors

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

  ViewVC Help
Powered by ViewVC