1 |
/*************************************************************************** |
2 |
* * |
3 |
* Copyright (C) 2008 - 2012 Andreas Persson * |
4 |
* Copyright (C) 2014 - 2016 Christian Schoenebeck * |
5 |
* * |
6 |
* This program is free software; you can redistribute it and/or modify * |
7 |
* it under the terms of the GNU General Public License as published by * |
8 |
* the Free Software Foundation; either version 2 of the License, or * |
9 |
* (at your option) any later version. * |
10 |
* * |
11 |
* This program is distributed in the hope that it will be useful, * |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 |
* GNU General Public License for more details. * |
15 |
* * |
16 |
* You should have received a copy of the GNU General Public License * |
17 |
* along with this program; if not, write to the Free Software * |
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, * |
19 |
* MA 02110-1301 USA * |
20 |
***************************************************************************/ |
21 |
|
22 |
#include "MidiInputDevicePlugin.h" |
23 |
#include "../../common/global_private.h" |
24 |
|
25 |
namespace LinuxSampler { |
26 |
|
27 |
// *************** MidiInputPortPlugin *************** |
28 |
// * |
29 |
|
30 |
MidiInputDevicePlugin::MidiInputPortPlugin::MidiInputPortPlugin(MidiInputDevicePlugin* pDevice, |
31 |
int portNumber) : |
32 |
MidiInputPort(pDevice, portNumber) { |
33 |
} |
34 |
|
35 |
|
36 |
|
37 |
// *************** ParameterPortsPlugin *************** |
38 |
// * |
39 |
|
40 |
void MidiInputDevicePlugin::ParameterPortsPlugin::ForceSetValue(int ports) { |
41 |
OnSetValue(ports); |
42 |
iVal = ports; |
43 |
} |
44 |
|
45 |
|
46 |
// *************** MidiInputDevicePlugin *************** |
47 |
// * |
48 |
|
49 |
MidiInputDevicePlugin::MidiInputDevicePlugin(std::map<String, DeviceCreationParameter*> Parameters, |
50 |
void* pSampler) : |
51 |
MidiInputDevice(Parameters, pSampler) { |
52 |
AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt()); |
53 |
} |
54 |
|
55 |
MidiInputDevicePlugin::~MidiInputDevicePlugin() { |
56 |
for (std::map<int, MidiInputPort*>::iterator iter = |
57 |
Ports.begin() ; iter != Ports.end() ; iter++) { |
58 |
delete dynamic_cast<MidiInputPortPlugin*>(iter->second); |
59 |
} |
60 |
Ports.clear(); |
61 |
} |
62 |
|
63 |
void MidiInputDevicePlugin::Listen() { |
64 |
} |
65 |
|
66 |
void MidiInputDevicePlugin::StopListen() { |
67 |
} |
68 |
|
69 |
String MidiInputDevicePlugin::Driver() { |
70 |
return Name(); |
71 |
} |
72 |
|
73 |
String MidiInputDevicePlugin::Name() { |
74 |
return "Plugin"; |
75 |
} |
76 |
|
77 |
String MidiInputDevicePlugin::Version() { |
78 |
String s = "$Revision$"; |
79 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
80 |
} |
81 |
|
82 |
String MidiInputDevicePlugin::Description() { |
83 |
return Name(); |
84 |
} |
85 |
|
86 |
MidiInputPort* MidiInputDevicePlugin::CreateMidiPort() { |
87 |
return new MidiInputPortPlugin(this, (int)Ports.size()); |
88 |
} |
89 |
|
90 |
void MidiInputDevicePlugin::AddMidiPort() { |
91 |
static_cast<ParameterPortsPlugin*>( |
92 |
Parameters["PORTS"])->ForceSetValue((int)Ports.size() + 1); |
93 |
} |
94 |
|
95 |
void MidiInputDevicePlugin::RemoveMidiPort(MidiInputPort* pPort) { |
96 |
// reorder map so pPort is last |
97 |
int portNumber = 0; |
98 |
std::map<int, MidiInputPort*>::iterator i = Ports.begin(); |
99 |
for ( ; i != Ports.end(); ++i, portNumber++) { |
100 |
if (i->second == pPort) break; |
101 |
} |
102 |
std::map<int, MidiInputPort*>::iterator previ = i; |
103 |
for (++i ; i != Ports.end(); ++i, portNumber++) { |
104 |
previ->second = i->second; |
105 |
static_cast<MidiInputPortPlugin*>(previ->second)->portNumber = portNumber; |
106 |
previ->second->PortParameters()["NAME"]->SetValue("Port " + ToString(portNumber)); |
107 |
previ = i; |
108 |
} |
109 |
previ->second = pPort; |
110 |
|
111 |
// delete the last port |
112 |
static_cast<ParameterPortsPlugin*>( |
113 |
Parameters["PORTS"])->ForceSetValue((int)Ports.size() - 1); |
114 |
} |
115 |
|
116 |
bool MidiInputDevicePlugin::isAutonomousDevice() { |
117 |
return false; |
118 |
} |
119 |
|
120 |
bool MidiInputDevicePlugin::isAutonomousDriver() { |
121 |
return false; |
122 |
} |
123 |
} |