1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2004 Grame * |
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 "MidiInputDeviceCoreMidi.h" |
25 |
#include "MidiInputDeviceFactory.h" |
26 |
|
27 |
namespace LinuxSampler { |
28 |
|
29 |
int MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::pPortID = 0; |
30 |
|
31 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterName::ParameterName(MidiInputPort* pPort) throw (LinuxSamplerException) : MidiInputPort::ParameterName(pPort, "Port " + ToString(pPort->GetPortNumber())) { |
32 |
OnSetValue(ValueAsString()); // initialize port name |
33 |
} |
34 |
|
35 |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterName::OnSetValue(String s) throw (LinuxSamplerException) { |
36 |
|
37 |
} |
38 |
|
39 |
// *************** ParameterCoreMidiBindings *************** |
40 |
// * |
41 |
|
42 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::ParameterCoreMidiBindings(MidiInputPortCoreMidi* pPort) : DeviceRuntimeParameterStrings( std::vector<String>() ) { |
43 |
this->pPort = pPort; |
44 |
} |
45 |
|
46 |
String MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::Description() { |
47 |
return "Bindings to other CoreMidi clients"; |
48 |
} |
49 |
bool MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::Fix() { |
50 |
return false; |
51 |
} |
52 |
|
53 |
std::vector<String> MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::PossibilitiesAsString() { |
54 |
std::vector<String> res; |
55 |
// Connections |
56 |
return res; |
57 |
} |
58 |
|
59 |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::OnSetValue(std::vector<String> vS) throw (LinuxSamplerException) { |
60 |
// to finish |
61 |
} |
62 |
|
63 |
|
64 |
// *************** MidiInputPortCoreMidi *************** |
65 |
// * |
66 |
|
67 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::MidiInputPortCoreMidi(MidiInputDeviceCoreMidi* pDevice) throw (MidiInputException) : MidiInputPort(pDevice, -1) { |
68 |
// create CoreMidi virtual destination |
69 |
|
70 |
MIDIDestinationCreate(pDevice->hCoreMidiClient, CFSTR("LinuxSampler_in"), ReadProc, this, &pDestination); |
71 |
if (!pDestination) throw MidiInputException("Error creating CoreMidi virtual destination"); |
72 |
this->portNumber = pPortID++; |
73 |
|
74 |
Parameters["NAME"] = new ParameterName(this); |
75 |
Parameters["CORE_MIDI_BINDINGS"] = new ParameterCoreMidiBindings(this); |
76 |
} |
77 |
|
78 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::~MidiInputPortCoreMidi() { |
79 |
MIDIEndpointDispose(pDestination); |
80 |
} |
81 |
|
82 |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ReadProc(const MIDIPacketList* pktlist, void* refCon, void* connRefCon) |
83 |
{ |
84 |
MidiInputPortCoreMidi* port = (MidiInputPortCoreMidi*)refCon; |
85 |
MIDIPacket *packet = (MIDIPacket *)pktlist->packet; |
86 |
|
87 |
for (unsigned int i = 0; i < pktlist->numPackets; ++i) { |
88 |
|
89 |
int cin = packet->data[0] & 0xF0; |
90 |
|
91 |
// To be checked : several events per packet |
92 |
|
93 |
switch(cin) { // status byte |
94 |
|
95 |
case 0xB0: |
96 |
port->DispatchControlChange(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
97 |
break; |
98 |
|
99 |
case 0xE0: |
100 |
port->DispatchPitchbend(packet->data[1],packet->data[0]&0x0F); |
101 |
break; |
102 |
|
103 |
case 0x90: |
104 |
if (packet->data[1] < 0x80) { |
105 |
if (packet->data[2] > 0){ |
106 |
port->DispatchNoteOn(packet->data[1],packet->data[2], packet->data[0]&0x0F); |
107 |
}else{ |
108 |
port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
109 |
} |
110 |
} |
111 |
break; |
112 |
|
113 |
case 0x80: |
114 |
if (packet->data[1] < 0x80) { |
115 |
port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
116 |
} |
117 |
break; |
118 |
} |
119 |
|
120 |
packet = MIDIPacketNext(packet); |
121 |
} |
122 |
} |
123 |
|
124 |
MidiInputDeviceCoreMidi::MidiInputDeviceCoreMidi(std::map<String,DeviceCreationParameter*> Parameters) : MidiInputDevice(Parameters) |
125 |
{ |
126 |
MIDIClientCreate(CFSTR("LinuxSampler"), NotifyProc, NULL, &hCoreMidiClient); |
127 |
if (!hCoreMidiClient) throw MidiInputException("Error opening CoreMidi client"); |
128 |
AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt()); |
129 |
} |
130 |
|
131 |
MidiInputDeviceCoreMidi::~MidiInputDeviceCoreMidi() |
132 |
{ |
133 |
if (hCoreMidiClient) { |
134 |
MIDIClientDispose(hCoreMidiClient); |
135 |
} |
136 |
} |
137 |
|
138 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi* MidiInputDeviceCoreMidi::CreateMidiPort() { |
139 |
return new MidiInputPortCoreMidi(this); |
140 |
} |
141 |
|
142 |
String MidiInputDeviceCoreMidi::Name() { |
143 |
return "CoreMidi"; |
144 |
} |
145 |
|
146 |
String MidiInputDeviceCoreMidi::Driver() { |
147 |
return Name(); |
148 |
} |
149 |
|
150 |
String MidiInputDeviceCoreMidi::Description() { |
151 |
return "Apple CoreMidi"; |
152 |
} |
153 |
|
154 |
String MidiInputDeviceCoreMidi::Version() { |
155 |
String s = "$Revision: 1.4 $"; |
156 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
157 |
} |
158 |
|
159 |
void MidiInputDeviceCoreMidi::NotifyProc(const MIDINotification* message, void* refCon) |
160 |
{ |
161 |
// to be finished |
162 |
if (message->messageID == kMIDIMsgSetupChanged) { |
163 |
printf("kMIDIMsgSetupChanged\n"); |
164 |
} |
165 |
} |
166 |
|
167 |
|
168 |
} // namespace LinuxSampler |