1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* Copyright (C) 2004, 2005 Grame * |
4 |
* * |
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
|
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
|
|
* Copyright (C) 2004 Grame * |
|
5 |
* * |
* * |
6 |
* This program is free software; you can redistribute it and/or modify * |
* 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 * |
* it under the terms of the GNU General Public License as published by * |
26 |
|
|
27 |
int MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::pPortID = 0; |
int MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::pPortID = 0; |
28 |
|
|
29 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterName::ParameterName(MidiInputPort* pPort) throw (LinuxSamplerException) : MidiInputPort::ParameterName(pPort, "Port " + ToString(pPort->GetPortNumber())) { |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterName::ParameterName(MidiInputPort* pPort) throw (Exception) : MidiInputPort::ParameterName(pPort, "Port " + ToString(pPort->GetPortNumber())) { |
30 |
OnSetValue(ValueAsString()); // initialize port name |
OnSetValue(ValueAsString()); // initialize port name |
31 |
} |
} |
32 |
|
|
33 |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterName::OnSetValue(String s) throw (LinuxSamplerException) { |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterName::OnSetValue(String s) throw (Exception) { |
34 |
|
|
35 |
} |
} |
36 |
|
|
37 |
// *************** ParameterCoreMidiBindings *************** |
// *************** ParameterCoreMidiBindings *************** |
38 |
// * |
// * |
39 |
|
|
54 |
return res; |
return res; |
55 |
} |
} |
56 |
|
|
57 |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::OnSetValue(std::vector<String> vS) throw (LinuxSamplerException) { |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::OnSetValue(std::vector<String> vS) throw (Exception) { |
58 |
// to finish |
// to finish |
59 |
} |
} |
60 |
|
|
64 |
|
|
65 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::MidiInputPortCoreMidi(MidiInputDeviceCoreMidi* pDevice) throw (MidiInputException) : MidiInputPort(pDevice, -1) { |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::MidiInputPortCoreMidi(MidiInputDeviceCoreMidi* pDevice) throw (MidiInputException) : MidiInputPort(pDevice, -1) { |
66 |
// create CoreMidi virtual destination |
// create CoreMidi virtual destination |
67 |
|
|
68 |
MIDIDestinationCreate(pDevice->hCoreMidiClient, CFSTR("LinuxSampler_in"), ReadProc, this, &pDestination); |
/* 20080105 Toshi Nagata */ |
69 |
|
char buf[32]; |
70 |
|
CFStringRef str; |
71 |
|
snprintf(buf, sizeof buf, "LinuxSampler_in_%d", pPortID); |
72 |
|
str = CFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8); |
73 |
|
MIDIDestinationCreate(pDevice->hCoreMidiClient, str, ReadProc, this, &pDestination); |
74 |
|
/* */ |
75 |
|
|
76 |
if (!pDestination) throw MidiInputException("Error creating CoreMidi virtual destination"); |
if (!pDestination) throw MidiInputException("Error creating CoreMidi virtual destination"); |
77 |
this->portNumber = pPortID++; |
this->portNumber = pPortID++; |
78 |
|
|
79 |
Parameters["NAME"] = new ParameterName(this); |
Parameters["NAME"] = new ParameterName(this); |
80 |
Parameters["CORE_MIDI_BINDINGS"] = new ParameterCoreMidiBindings(this); |
Parameters["CORE_MIDI_BINDINGS"] = new ParameterCoreMidiBindings(this); |
81 |
} |
} |
83 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::~MidiInputPortCoreMidi() { |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::~MidiInputPortCoreMidi() { |
84 |
MIDIEndpointDispose(pDestination); |
MIDIEndpointDispose(pDestination); |
85 |
} |
} |
86 |
|
|
87 |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ReadProc(const MIDIPacketList* pktlist, void* refCon, void* connRefCon) |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ReadProc(const MIDIPacketList* pktlist, void* refCon, void* connRefCon) |
88 |
{ |
{ |
89 |
MidiInputPortCoreMidi* port = (MidiInputPortCoreMidi*)refCon; |
MidiInputPortCoreMidi* port = (MidiInputPortCoreMidi*)refCon; |
90 |
MIDIPacket *packet = (MIDIPacket *)pktlist->packet; |
MIDIPacket *packet = (MIDIPacket *)pktlist->packet; |
91 |
|
|
92 |
for (unsigned int i = 0; i < pktlist->numPackets; ++i) { |
for (unsigned int i = 0; i < pktlist->numPackets; ++i) { |
93 |
|
|
94 |
int cin = packet->data[0] & 0xF0; |
int cin = packet->data[0] & 0xF0; |
95 |
|
|
96 |
// To be checked : several events per packet |
// To be checked : several events per packet |
97 |
|
|
98 |
switch(cin) { // status byte |
switch(cin) { // status byte |
99 |
|
|
100 |
case 0xB0: |
case 0xB0: |
101 |
port->DispatchControlChange(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
if (packet->data[1] == 0) |
102 |
|
port->DispatchBankSelectMsb(packet->data[2],packet->data[0]&0x0F); |
103 |
|
else if (packet->data[1] == 32) |
104 |
|
port->DispatchBankSelectLsb(packet->data[2],packet->data[0]&0x0F); |
105 |
|
else |
106 |
|
port->DispatchControlChange(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
107 |
break; |
break; |
108 |
|
|
109 |
|
case 0xD0: |
110 |
|
port->DispatchControlChange(128,packet->data[1],packet->data[0]&0x0F); |
111 |
|
break; |
112 |
|
|
113 |
case 0xE0: |
case 0xE0: |
114 |
port->DispatchPitchbend(packet->data[1],packet->data[0]&0x0F); |
port->DispatchPitchbend(packet->data[1],packet->data[0]&0x0F); |
115 |
break; |
break; |
123 |
} |
} |
124 |
} |
} |
125 |
break; |
break; |
126 |
|
|
127 |
case 0x80: |
case 0x80: |
128 |
if (packet->data[1] < 0x80) { |
if (packet->data[1] < 0x80) { |
129 |
port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
130 |
} |
} |
131 |
break; |
break; |
132 |
|
|
133 |
|
case 0xC0: |
134 |
|
if (packet->data[1] < 0x80) { |
135 |
|
port->DispatchProgramChange(packet->data[1], packet->data[0] & 0x0F); |
136 |
|
} |
137 |
|
break; |
138 |
} |
} |
139 |
|
|
140 |
packet = MIDIPacketNext(packet); |
packet = MIDIPacketNext(packet); |
141 |
} |
} |
142 |
} |
} |
143 |
|
|
144 |
MidiInputDeviceCoreMidi::MidiInputDeviceCoreMidi(std::map<String,DeviceCreationParameter*> Parameters) : MidiInputDevice(Parameters) |
|
145 |
|
// *************** MidiInputDeviceCoreMidi *************** |
146 |
|
// * |
147 |
|
|
148 |
|
MidiInputDeviceCoreMidi::MidiInputDeviceCoreMidi(std::map<String,DeviceCreationParameter*> Parameters, void* pSampler) : MidiInputDevice(Parameters, pSampler) |
149 |
{ |
{ |
150 |
MIDIClientCreate(CFSTR("LinuxSampler"), NotifyProc, NULL, &hCoreMidiClient); |
MIDIClientCreate(CFSTR("LinuxSampler"), NotifyProc, NULL, &hCoreMidiClient); |
151 |
if (!hCoreMidiClient) throw MidiInputException("Error opening CoreMidi client"); |
if (!hCoreMidiClient) throw MidiInputException("Error opening CoreMidi client"); |
152 |
AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt()); |
AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt()); |
153 |
} |
} |
154 |
|
|
155 |
MidiInputDeviceCoreMidi::~MidiInputDeviceCoreMidi() |
MidiInputDeviceCoreMidi::~MidiInputDeviceCoreMidi() |
156 |
{ |
{ |
157 |
if (hCoreMidiClient) { |
if (hCoreMidiClient) { |
158 |
MIDIClientDispose(hCoreMidiClient); |
MIDIClientDispose(hCoreMidiClient); |
159 |
} |
} |
160 |
} |
} |
161 |
|
|
162 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi* MidiInputDeviceCoreMidi::CreateMidiPort() { |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi* MidiInputDeviceCoreMidi::CreateMidiPort() { |
163 |
return new MidiInputPortCoreMidi(this); |
return new MidiInputPortCoreMidi(this); |
164 |
} |
} |
165 |
|
|
166 |
String MidiInputDeviceCoreMidi::Name() { |
String MidiInputDeviceCoreMidi::Name() { |
167 |
return "COREMIDI"; |
return "COREMIDI"; |
168 |
} |
} |
170 |
String MidiInputDeviceCoreMidi::Driver() { |
String MidiInputDeviceCoreMidi::Driver() { |
171 |
return Name(); |
return Name(); |
172 |
} |
} |
173 |
|
|
174 |
String MidiInputDeviceCoreMidi::Description() { |
String MidiInputDeviceCoreMidi::Description() { |
175 |
return "Apple CoreMidi"; |
return "Apple CoreMidi"; |
176 |
} |
} |
177 |
|
|
178 |
String MidiInputDeviceCoreMidi::Version() { |
String MidiInputDeviceCoreMidi::Version() { |
179 |
String s = "$Revision: 1.5 $"; |
String s = "$Revision: 1.10 $"; |
180 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
181 |
} |
} |
182 |
|
|
187 |
printf("kMIDIMsgSetupChanged\n"); |
printf("kMIDIMsgSetupChanged\n"); |
188 |
} |
} |
189 |
} |
} |
190 |
|
|
191 |
|
|
192 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |