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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 947 - (hide annotations) (download)
Mon Nov 27 21:34:55 2006 UTC (17 years, 5 months ago) by schoenebeck
File size: 6830 byte(s)
* implemented MIDI instrument mapping according to latest LSCP draft

1 schoenebeck 201 /***************************************************************************
2     * *
3 schoenebeck 551 * Copyright (C) 2004, 2005 Grame *
4 schoenebeck 201 * *
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 letz 362 #include "MidiInputDeviceFactory.h"
23 schoenebeck 201
24     namespace LinuxSampler {
25    
26 letz 362 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 schoenebeck 551
34     }
35    
36 letz 362 // *************** ParameterCoreMidiBindings ***************
37     // *
38    
39     MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::ParameterCoreMidiBindings(MidiInputPortCoreMidi* pPort) : DeviceRuntimeParameterStrings( std::vector<String>() ) {
40     this->pPort = pPort;
41 schoenebeck 201 }
42    
43 letz 362 String MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::Description() {
44     return "Bindings to other CoreMidi clients";
45 schoenebeck 201 }
46 letz 362 bool MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ParameterCoreMidiBindings::Fix() {
47     return false;
48     }
49 schoenebeck 201
50 letz 362 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 schoenebeck 551
67 letz 362 MIDIDestinationCreate(pDevice->hCoreMidiClient, CFSTR("LinuxSampler_in"), ReadProc, this, &pDestination);
68     if (!pDestination) throw MidiInputException("Error creating CoreMidi virtual destination");
69     this->portNumber = pPortID++;
70 schoenebeck 551
71 letz 362 Parameters["NAME"] = new ParameterName(this);
72     Parameters["CORE_MIDI_BINDINGS"] = new ParameterCoreMidiBindings(this);
73 schoenebeck 201 }
74    
75 letz 362 MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::~MidiInputPortCoreMidi() {
76     MIDIEndpointDispose(pDestination);
77     }
78 schoenebeck 551
79 letz 362 void MidiInputDeviceCoreMidi::MidiInputPortCoreMidi::ReadProc(const MIDIPacketList* pktlist, void* refCon, void* connRefCon)
80 schoenebeck 201 {
81 letz 362 MidiInputPortCoreMidi* port = (MidiInputPortCoreMidi*)refCon;
82 schoenebeck 551 MIDIPacket *packet = (MIDIPacket *)pktlist->packet;
83 letz 362
84     for (unsigned int i = 0; i < pktlist->numPackets; ++i) {
85 schoenebeck 551
86 schoenebeck 201 int cin = packet->data[0] & 0xF0;
87 schoenebeck 551
88 schoenebeck 201 // To be checked : several events per packet
89 schoenebeck 551
90 schoenebeck 201 switch(cin) { // status byte
91 schoenebeck 551
92 schoenebeck 201 case 0xB0:
93 schoenebeck 947 if (packet->data[1] == 0)
94     port->DispatchBankSelectMsb(packet->data[2],packet->data[0]&0x0F);
95     else if (packet->data[1] == 32)
96     port->DispatchBankSelectLsb(packet->data[2],packet->data[0]&0x0F);
97     else
98     port->DispatchControlChange(packet->data[1],packet->data[2],packet->data[0]&0x0F);
99 schoenebeck 201 break;
100 schoenebeck 551
101 persson 903 case 0xD0:
102     port->DispatchControlChange(128,packet->data[1],packet->data[0]&0x0F);
103     break;
104    
105 schoenebeck 201 case 0xE0:
106 letz 362 port->DispatchPitchbend(packet->data[1],packet->data[0]&0x0F);
107 schoenebeck 201 break;
108    
109     case 0x90:
110 letz 362 if (packet->data[1] < 0x80) {
111 schoenebeck 201 if (packet->data[2] > 0){
112 letz 362 port->DispatchNoteOn(packet->data[1],packet->data[2], packet->data[0]&0x0F);
113 schoenebeck 201 }else{
114 letz 362 port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F);
115 schoenebeck 201 }
116     }
117     break;
118 schoenebeck 551
119 schoenebeck 201 case 0x80:
120 letz 362 if (packet->data[1] < 0x80) {
121     port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F);
122 schoenebeck 201 }
123     break;
124 schoenebeck 551
125     case 0xC0:
126     if (packet->data[1] < 0x80) {
127     port->DispatchProgramChange(packet->data[1], packet->data[0] & 0x0F);
128     }
129     break;
130 schoenebeck 201 }
131 schoenebeck 551
132 schoenebeck 201 packet = MIDIPacketNext(packet);
133 schoenebeck 551 }
134 letz 362 }
135    
136 schoenebeck 551
137     // *************** MidiInputDeviceCoreMidi ***************
138     // *
139    
140     MidiInputDeviceCoreMidi::MidiInputDeviceCoreMidi(std::map<String,DeviceCreationParameter*> Parameters, void* pSampler) : MidiInputDevice(Parameters, pSampler)
141 letz 362 {
142     MIDIClientCreate(CFSTR("LinuxSampler"), NotifyProc, NULL, &hCoreMidiClient);
143     if (!hCoreMidiClient) throw MidiInputException("Error opening CoreMidi client");
144     AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt());
145     }
146    
147 schoenebeck 551 MidiInputDeviceCoreMidi::~MidiInputDeviceCoreMidi()
148 letz 362 {
149     if (hCoreMidiClient) {
150     MIDIClientDispose(hCoreMidiClient);
151 schoenebeck 201 }
152 letz 362 }
153 schoenebeck 551
154 letz 362 MidiInputDeviceCoreMidi::MidiInputPortCoreMidi* MidiInputDeviceCoreMidi::CreateMidiPort() {
155     return new MidiInputPortCoreMidi(this);
156     }
157 schoenebeck 551
158 letz 362 String MidiInputDeviceCoreMidi::Name() {
159 letz 509 return "COREMIDI";
160 letz 362 }
161    
162     String MidiInputDeviceCoreMidi::Driver() {
163     return Name();
164     }
165 schoenebeck 551
166 letz 362 String MidiInputDeviceCoreMidi::Description() {
167     return "Apple CoreMidi";
168     }
169    
170     String MidiInputDeviceCoreMidi::Version() {
171 schoenebeck 947 String s = "$Revision: 1.8 $";
172 letz 362 return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword
173     }
174    
175     void MidiInputDeviceCoreMidi::NotifyProc(const MIDINotification* message, void* refCon)
176     {
177     // to be finished
178     if (message->messageID == kMIDIMsgSetupChanged) {
179     printf("kMIDIMsgSetupChanged\n");
180     }
181 schoenebeck 201 }
182    
183 schoenebeck 551
184 schoenebeck 201 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC