/[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 551 - (show annotations) (download)
Tue May 17 18:16:54 2005 UTC (18 years, 11 months ago) by schoenebeck
File size: 5947 byte(s)
* Implemented MIDI program change as general, engine independant solution.
  The program number will determine the sampler channel to which the MIDI
  device will be connected to and the given MIDI channel defines on which
  MIDI channel that sampler channel should listen to. Also the program
  change will disconnect probably established connection from the previous
  program change event.

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 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 (LinuxSamplerException) {
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 (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 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 Parameters.erase(iter);
133 delete iter->second;
134 iter++;
135 }
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 Ports.erase(portsIter);
157 delete portsIter->second;
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