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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 880 - (show annotations) (download)
Tue Jun 27 22:57:37 2006 UTC (17 years, 9 months ago) by schoenebeck
File size: 5942 byte(s)
just some refactoring work:
- renamed class LinuxSamplerException -> Exception
- encapsulated LS API relevant files into LS namespace
- removed unnecessary header inclusions

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005, 2006 Christian Schoenebeck *
7 * *
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 // *************** ParameterActive ***************
29 // *
30
31 MidiInputDevice::ParameterActive::ParameterActive() : DeviceCreationParameterBool() {
32 InitWithDefault();
33 }
34
35 MidiInputDevice::ParameterActive::ParameterActive(String active) : DeviceCreationParameterBool(active) {
36 }
37
38 String MidiInputDevice::ParameterActive::Description() {
39 return "Enable / disable device";
40 }
41
42 bool MidiInputDevice::ParameterActive::Fix() {
43 return false;
44 }
45
46 bool MidiInputDevice::ParameterActive::Mandatory() {
47 return false;
48 }
49
50 std::map<String,DeviceCreationParameter*> MidiInputDevice::ParameterActive::DependsAsParameters() {
51 return std::map<String,DeviceCreationParameter*>();
52 }
53
54 optional<bool> MidiInputDevice::ParameterActive::DefaultAsBool(std::map<String,String> Parameters) {
55 return true;
56 }
57
58 void MidiInputDevice::ParameterActive::OnSetValue(bool b) throw (Exception) {
59 if (b) ((MidiInputDevice*)pDevice)->Listen();
60 else ((MidiInputDevice*)pDevice)->StopListen();
61 }
62
63 String MidiInputDevice::ParameterActive::Name() {
64 return "ACTIVE";
65 }
66
67
68
69 // *************** ParameterPorts ***************
70 // *
71
72 MidiInputDevice::ParameterPorts::ParameterPorts() : DeviceCreationParameterInt() {
73 InitWithDefault();
74 }
75
76 MidiInputDevice::ParameterPorts::ParameterPorts(String val) : DeviceCreationParameterInt(val) {
77 }
78
79 String MidiInputDevice::ParameterPorts::Description() {
80 return "Number of ports";
81 }
82
83 bool MidiInputDevice::ParameterPorts::Fix() {
84 return false;
85 }
86
87 bool MidiInputDevice::ParameterPorts::Mandatory() {
88 return false;
89 }
90
91 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 return 1;
97 }
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 (Exception) {
112 ((MidiInputDevice*)pDevice)->AcquirePorts(i);
113 }
114
115 String MidiInputDevice::ParameterPorts::Name() {
116 return "PORTS";
117 }
118
119
120
121 // *************** MidiInputDevice ***************
122 // *
123
124 MidiInputDevice::MidiInputDevice(std::map<String,DeviceCreationParameter*> DriverParameters, void* pSampler) {
125 this->Parameters = DriverParameters;
126 this->pSampler = pSampler;
127 }
128
129 MidiInputDevice::~MidiInputDevice() {
130 std::map<String,DeviceCreationParameter*>::iterator iter = Parameters.begin();
131 while (iter != Parameters.end()) {
132 delete iter->second;
133 iter++;
134 }
135 Parameters.clear();
136 }
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 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 delete portsIter->second;
157 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