/[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 1715 - (show annotations) (download)
Tue Mar 11 15:20:46 2008 UTC (16 years, 1 month ago) by schoenebeck
File size: 7013 byte(s)
* dispatch bank select as ordinary CC as well, the user might seriously
  want to (mis)use it for some purpose ("fixed" in all current MIDI
  input drivers: ALSA, CoreMIDI, JACK, MidiShare, MME)
* minor fix: only mark FX sends as being modified if really the
  respective FX send MIDI controller was used

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

  ViewVC Help
Powered by ViewVC