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 0xE0: |
case 0xE0: |
97 |
port->DispatchPitchbend(packet->data[1],packet->data[0]&0x0F); |
port->DispatchPitchbend(packet->data[1],packet->data[0]&0x0F); |
98 |
break; |
break; |
106 |
} |
} |
107 |
} |
} |
108 |
break; |
break; |
109 |
|
|
110 |
case 0x80: |
case 0x80: |
111 |
if (packet->data[1] < 0x80) { |
if (packet->data[1] < 0x80) { |
112 |
port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F); |
113 |
} |
} |
114 |
break; |
break; |
115 |
|
|
116 |
|
case 0xC0: |
117 |
|
if (packet->data[1] < 0x80) { |
118 |
|
port->DispatchProgramChange(packet->data[1], packet->data[0] & 0x0F); |
119 |
|
} |
120 |
|
break; |
121 |
} |
} |
122 |
|
|
123 |
packet = MIDIPacketNext(packet); |
packet = MIDIPacketNext(packet); |
124 |
} |
} |
125 |
} |
} |
126 |
|
|
127 |
MidiInputDeviceCoreMidi::MidiInputDeviceCoreMidi(std::map<String,DeviceCreationParameter*> Parameters) : MidiInputDevice(Parameters) |
|
128 |
|
// *************** MidiInputDeviceCoreMidi *************** |
129 |
|
// * |
130 |
|
|
131 |
|
MidiInputDeviceCoreMidi::MidiInputDeviceCoreMidi(std::map<String,DeviceCreationParameter*> Parameters, void* pSampler) : MidiInputDevice(Parameters, pSampler) |
132 |
{ |
{ |
133 |
MIDIClientCreate(CFSTR("LinuxSampler"), NotifyProc, NULL, &hCoreMidiClient); |
MIDIClientCreate(CFSTR("LinuxSampler"), NotifyProc, NULL, &hCoreMidiClient); |
134 |
if (!hCoreMidiClient) throw MidiInputException("Error opening CoreMidi client"); |
if (!hCoreMidiClient) throw MidiInputException("Error opening CoreMidi client"); |
135 |
AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt()); |
AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt()); |
136 |
} |
} |
137 |
|
|
138 |
MidiInputDeviceCoreMidi::~MidiInputDeviceCoreMidi() |
MidiInputDeviceCoreMidi::~MidiInputDeviceCoreMidi() |
139 |
{ |
{ |
140 |
if (hCoreMidiClient) { |
if (hCoreMidiClient) { |
141 |
MIDIClientDispose(hCoreMidiClient); |
MIDIClientDispose(hCoreMidiClient); |
142 |
} |
} |
143 |
} |
} |
144 |
|
|
145 |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi* MidiInputDeviceCoreMidi::CreateMidiPort() { |
MidiInputDeviceCoreMidi::MidiInputPortCoreMidi* MidiInputDeviceCoreMidi::CreateMidiPort() { |
146 |
return new MidiInputPortCoreMidi(this); |
return new MidiInputPortCoreMidi(this); |
147 |
} |
} |
148 |
|
|
149 |
String MidiInputDeviceCoreMidi::Name() { |
String MidiInputDeviceCoreMidi::Name() { |
150 |
return "COREMIDI"; |
return "COREMIDI"; |
151 |
} |
} |
153 |
String MidiInputDeviceCoreMidi::Driver() { |
String MidiInputDeviceCoreMidi::Driver() { |
154 |
return Name(); |
return Name(); |
155 |
} |
} |
156 |
|
|
157 |
String MidiInputDeviceCoreMidi::Description() { |
String MidiInputDeviceCoreMidi::Description() { |
158 |
return "Apple CoreMidi"; |
return "Apple CoreMidi"; |
159 |
} |
} |
160 |
|
|
161 |
String MidiInputDeviceCoreMidi::Version() { |
String MidiInputDeviceCoreMidi::Version() { |
162 |
String s = "$Revision: 1.5 $"; |
String s = "$Revision: 1.6 $"; |
163 |
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 |
164 |
} |
} |
165 |
|
|
170 |
printf("kMIDIMsgSetupChanged\n"); |
printf("kMIDIMsgSetupChanged\n"); |
171 |
} |
} |
172 |
} |
} |
173 |
|
|
174 |
|
|
175 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |