/[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 1149 - (hide annotations) (download)
Sat Apr 7 22:32:47 2007 UTC (17 years ago) by schoenebeck
File size: 6871 byte(s)
* minor fix of EGDecay
* fixed compilation errors regarding OSX
(patch by Toshi Nagata)

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

  ViewVC Help
Powered by ViewVC