/[svn]/linuxsampler/trunk/src/drivers/midi/MidiInputDeviceCoreMidi.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/drivers/midi/MidiInputDeviceCoreMidi.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 903 - (show annotations) (download)
Sat Jul 22 14:22:53 2006 UTC (17 years, 9 months ago) by persson
File size: 6605 byte(s)
* real support for 24 bit samples - samples are not truncated to 16
  bits anymore
* support for aftertouch (channel pressure, not polyphonic aftertouch)

1 /***************************************************************************
2 * *
3 * Copyright (C) 2004, 2005 Grame *
4 * *
5 * 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 *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18 * MA 02111-1307 USA *
19 ***************************************************************************/
20
21 #include "MidiInputDeviceCoreMidi.h"
22 #include "MidiInputDeviceFactory.h"
23
24 namespace LinuxSampler {
25
26 int MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::pPortID = 0;
27
28 MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterName::ParameterName(MidiInputPort* pPort) throw (LinuxSamplerException) : MidiInputPort::ParameterName(pPort, "Port " + ToString(pPort->GetPortNumber())) {
29 OnSetValue(ValueAsString()); // initialize port name
30 }
31
32 void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterName::OnSetValue(String s) throw (LinuxSamplerException) {
33
34 }
35
36 // *************** ParameterCoreMidiBindings ***************
37 // *
38
39 MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::ParameterCoreMidiBindings(MidiInputPortCoreMidi* pPort) : DeviceRuntimeParameterStrings( std::vector<String>() ) {
40 this->pPort = pPort;
41 }
42
43 String MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::Description() {
44 return "Bindings to other CoreMidi clients";
45 }
46 bool MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::Fix() {
47 return false;
48 }
49
50 std::vector<String> MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::PossibilitiesAsString() {
51 std::vector<String> res;
52 // Connections
53 return res;
54 }
55
56 void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::OnSetValue(std::vector<String> vS) throw (LinuxSamplerException) {
57 // to finish
58 }
59
60
61 // *************** MidiInputPortCoreMidi ***************
62 // *
63
64 MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::MidiInputPortCoreMidi(MidiInputDeviceCoreMidi* pDevice) throw (MidiInputException) : MidiInputPort(pDevice, -1) {
65 // create CoreMidi virtual destination
66
67 MIDIDestinationCreate(pDevice->hCoreMidiClient, CFSTR("LinuxSampler_in"), ReadProc, this, &pDestination);
68 if (!pDestination) throw MidiInputException("Error creating CoreMidi virtual destination");
69 this->portNumber = pPortID++;
70
71 Parameters["NAME"] = new ParameterName(this);
72 Parameters["CORE_MIDI_BINDINGS"] = new ParameterCoreMidiBindings(this);
73 }
74
75 MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::~MidiInputPortCoreMidi() {
76 MIDIEndpointDispose(pDestination);
77 }
78
79 void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ReadProc(const MIDIPacketList* pktlist, void* refCon, void* connRefCon)
80 {
81 MidiInputPortCoreMidi* port = (MidiInputPortCoreMidi*)refCon;
82 MIDIPacket *packet = (MIDIPacket *)pktlist->packet;
83
84 for (unsigned int i = 0; i < pktlist->numPackets; ++i) {
85
86 int cin = packet->data[0] & 0xF0;
87
88 // To be checked : several events per packet
89
90 switch(cin) { // status byte
91
92 case 0xB0:
93 port->DispatchControlChange(packet->data[1],packet->data[2],packet->data[0]&0x0F);
94 break;
95
96 case 0xD0:
97 port->DispatchControlChange(128,packet->data[1],packet->data[0]&0x0F);
98 break;
99
100 case 0xE0:
101 port->DispatchPitchbend(packet->data[1],packet->data[0]&0x0F);
102 break;
103
104 case 0x90:
105 if (packet->data[1] < 0x80) {
106 if (packet->data[2] > 0){
107 port->DispatchNoteOn(packet->data[1],packet->data[2], packet->data[0]&0x0F);
108 }else{
109 port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F);
110 }
111 }
112 break;
113
114 case 0x80:
115 if (packet->data[1] < 0x80) {
116 port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F);
117 }
118 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);
128 }
129 }
130
131
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);
138 if (!hCoreMidiClient) throw MidiInputException("Error opening CoreMidi client");
139 AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt());
140 }
141
142 MidiInputDeviceCoreMidi::~MidiInputDeviceCoreMidi()
143 {
144 if (hCoreMidiClient) {
145 MIDIClientDispose(hCoreMidiClient);
146 }
147 }
148
149 MidiInputDeviceCoreMidi::MidiInputPortCoreMidi* MidiInputDeviceCoreMidi::CreateMidiPort() {
150 return new MidiInputPortCoreMidi(this);
151 }
152
153 String MidiInputDeviceCoreMidi::Name() {
154 return "COREMIDI";
155 }
156
157 String MidiInputDeviceCoreMidi::Driver() {
158 return Name();
159 }
160
161 String MidiInputDeviceCoreMidi::Description() {
162 return "Apple CoreMidi";
163 }
164
165 String MidiInputDeviceCoreMidi::Version() {
166 String s = "$Revision: 1.7 $";
167 return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
168 }
169
170 void MidiInputDeviceCoreMidi::NotifyProc(const MIDINotification* message, void* refCon)
171 {
172 // to be finished
173 if (message->messageID == kMIDIMsgSetupChanged) {
174 printf("kMIDIMsgSetupChanged\n");
175 }
176 }
177
178
179 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC