1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* Copyright (C) 2004, 2005 Grame * |
|
* * |
|
|
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
|
|
* Copyright (C) 2004 Grame * |
|
4 |
* * |
* * |
5 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
6 |
* 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 * |
30 |
} |
} |
31 |
|
|
32 |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterName::OnSetValue(String s) throw (LinuxSamplerException) { |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterName::OnSetValue(String s) throw (LinuxSamplerException) { |
33 |
|
|
34 |
} |
} |
35 |
|
|
36 |
// *************** ParameterCoreMidiBindings *************** |
// *************** ParameterCoreMidiBindings *************** |
37 |
// * |
// * |
38 |
|
|
63 |
|
|
64 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::MidiInputPortCoreMidi(MidiInputDeviceCoreMidi* pDevice) throw (MidiInputException) : MidiInputPort(pDevice, -1) { |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::MidiInputPortCoreMidi(MidiInputDeviceCoreMidi* pDevice) throw (MidiInputException) : MidiInputPort(pDevice, -1) { |
65 |
// create CoreMidi virtual destination |
// create CoreMidi virtual destination |
66 |
|
|
67 |
MIDIDestinationCreate(pDevice->hCoreMidiClient, CFSTR("LinuxSampler_in"), ReadProc, this, &pDestination); |
MIDIDestinationCreate(pDevice->hCoreMidiClient, CFSTR("LinuxSampler_in"), ReadProc, this, &pDestination); |
68 |
if (!pDestination) throw MidiInputException("Error creating CoreMidi virtual destination"); |
if (!pDestination) throw MidiInputException("Error creating CoreMidi virtual destination"); |
69 |
this->portNumber = pPortID++; |
this->portNumber = pPortID++; |
70 |
|
|
71 |
Parameters["NAME"] = new ParameterName(this); |
Parameters["NAME"] = new ParameterName(this); |
72 |
Parameters["CORE_MIDI_BINDINGS"] = new ParameterCoreMidiBindings(this); |
Parameters["CORE_MIDI_BINDINGS"] = new ParameterCoreMidiBindings(this); |
73 |
} |
} |
75 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::~MidiInputPortCoreMidi() { |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::~MidiInputPortCoreMidi() { |
76 |
MIDIEndpointDispose(pDestination); |
MIDIEndpointDispose(pDestination); |
77 |
} |
} |
78 |
|
|
79 |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ReadProc(const MIDIPacketList* pktlist, void* refCon, void* connRefCon) |
void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ReadProc(const MIDIPacketList* pktlist, void* refCon, void* connRefCon) |
80 |
{ |
{ |
81 |
MidiInputPortCoreMidi* port = (MidiInputPortCoreMidi*)refCon; |
MidiInputPortCoreMidi* port = (MidiInputPortCoreMidi*)refCon; |
82 |
MIDIPacket *packet = (MIDIPacket *)pktlist->packet; |
MIDIPacket *packet = (MIDIPacket *)pktlist->packet; |
83 |
|
|
84 |
for (unsigned int i = 0; i < pktlist->numPackets; ++i) { |
for (unsigned int i = 0; i < pktlist->numPackets; ++i) { |
85 |
|
|
86 |
int cin = packet->data[0] & 0xF0; |
int cin = packet->data[0] & 0xF0; |
87 |
|
|
88 |
// To be checked : several events per packet |
// To be checked : several events per packet |
89 |
|
|
90 |
switch(cin) { // status byte |
switch(cin) { // status byte |
91 |
|
|
92 |
case 0xB0: |
case 0xB0: |
93 |
port->DispatchControlChange(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
port->DispatchControlChange(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
94 |
break; |
break; |
95 |
|
|
96 |
|
case 0xD0: |
97 |
|
port->DispatchControlChange(128,packet->data[1],packet->data[0]&0x0F); |
98 |
|
break; |
99 |
|
|
100 |
case 0xE0: |
case 0xE0: |
101 |
port->DispatchPitchbend(packet->data[1],packet->data[0]&0x0F); |
port->DispatchPitchbend(packet->data[1],packet->data[0]&0x0F); |
102 |
break; |
break; |
110 |
} |
} |
111 |
} |
} |
112 |
break; |
break; |
113 |
|
|
114 |
case 0x80: |
case 0x80: |
115 |
if (packet->data[1] < 0x80) { |
if (packet->data[1] < 0x80) { |
116 |
port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
117 |
} |
} |
118 |
break; |
break; |
119 |
|
|
120 |
|
case 0xC0: |
121 |
|
if (packet->data[1] < 0x80) { |
122 |
|
port->DispatchProgramChange(packet->data[1], packet->data[0] & 0x0F); |
123 |
|
} |
124 |
|
break; |
125 |
} |
} |
126 |
|
|
127 |
packet = MIDIPacketNext(packet); |
packet = MIDIPacketNext(packet); |
128 |
} |
} |
129 |
} |
} |
130 |
|
|
131 |
MidiInputDeviceCoreMidi::MidiInputDeviceCoreMidi(std::map<String,DeviceCreationParameter*> Parameters) : MidiInputDevice(Parameters) |
|
132 |
|
// *************** MidiInputDeviceCoreMidi *************** |
133 |
|
// * |
134 |
|
|
135 |
|
MidiInputDeviceCoreMidi::MidiInputDeviceCoreMidi(std::map<String,DeviceCreationParameter*> Parameters, void* pSampler) : MidiInputDevice(Parameters, pSampler) |
136 |
{ |
{ |
137 |
MIDIClientCreate(CFSTR("LinuxSampler"), NotifyProc, NULL, &hCoreMidiClient); |
MIDIClientCreate(CFSTR("LinuxSampler"), NotifyProc, NULL, &hCoreMidiClient); |
138 |
if (!hCoreMidiClient) throw MidiInputException("Error opening CoreMidi client"); |
if (!hCoreMidiClient) throw MidiInputException("Error opening CoreMidi client"); |
139 |
AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt()); |
AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt()); |
140 |
} |
} |
141 |
|
|
142 |
MidiInputDeviceCoreMidi::~MidiInputDeviceCoreMidi() |
MidiInputDeviceCoreMidi::~MidiInputDeviceCoreMidi() |
143 |
{ |
{ |
144 |
if (hCoreMidiClient) { |
if (hCoreMidiClient) { |
145 |
MIDIClientDispose(hCoreMidiClient); |
MIDIClientDispose(hCoreMidiClient); |
146 |
} |
} |
147 |
} |
} |
148 |
|
|
149 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi* MidiInputDeviceCoreMidi::CreateMidiPort() { |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi* MidiInputDeviceCoreMidi::CreateMidiPort() { |
150 |
return new MidiInputPortCoreMidi(this); |
return new MidiInputPortCoreMidi(this); |
151 |
} |
} |
152 |
|
|
153 |
String MidiInputDeviceCoreMidi::Name() { |
String MidiInputDeviceCoreMidi::Name() { |
154 |
return "COREMIDI"; |
return "COREMIDI"; |
155 |
} |
} |
157 |
String MidiInputDeviceCoreMidi::Driver() { |
String MidiInputDeviceCoreMidi::Driver() { |
158 |
return Name(); |
return Name(); |
159 |
} |
} |
160 |
|
|
161 |
String MidiInputDeviceCoreMidi::Description() { |
String MidiInputDeviceCoreMidi::Description() { |
162 |
return "Apple CoreMidi"; |
return "Apple CoreMidi"; |
163 |
} |
} |
164 |
|
|
165 |
String MidiInputDeviceCoreMidi::Version() { |
String MidiInputDeviceCoreMidi::Version() { |
166 |
String s = "$Revision: 1.5 $"; |
String s = "$Revision: 1.7 $"; |
167 |
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 |
168 |
} |
} |
169 |
|
|
174 |
printf("kMIDIMsgSetupChanged\n"); |
printf("kMIDIMsgSetupChanged\n"); |
175 |
} |
} |
176 |
} |
} |
177 |
|
|
178 |
|
|
179 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |