/[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 903 - (hide 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 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 letz 362 port->DispatchControlChange(packet->data[1],packet->data[2],packet->data[0]&0x0F);
94 schoenebeck 201 break;
95 schoenebeck 551
96 persson 903 case 0xD0:
97     port->DispatchControlChange(128,packet->data[1],packet->data[0]&0x0F);
98     break;
99    
100 schoenebeck 201 case 0xE0:
101 letz 362 port->DispatchPitchbend(packet->data[1],packet->data[0]&0x0F);
102 schoenebeck 201 break;
103    
104     case 0x90:
105 letz 362 if (packet->data[1] < 0x80) {
106 schoenebeck 201 if (packet->data[2] > 0){
107 letz 362 port->DispatchNoteOn(packet->data[1],packet->data[2], packet->data[0]&0x0F);
108 schoenebeck 201 }else{
109 letz 362 port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F);
110 schoenebeck 201 }
111     }
112     break;
113 schoenebeck 551
114 schoenebeck 201 case 0x80:
115 letz 362 if (packet->data[1] < 0x80) {
116     port->DispatchNoteOff(packet->data[1],packet->data[2],packet->data[0]&0x0F);
117 schoenebeck 201 }
118     break;
119 schoenebeck 551
120     case 0xC0:
121     if (packet->data[1] < 0x80) {
122     port->DispatchProgramChange(packet->data[1], packet->data[0] & 0x0F);
123     }
124     break;
125 schoenebeck 201 }
126 schoenebeck 551
127 schoenebeck 201 packet = MIDIPacketNext(packet);
128 schoenebeck 551 }
129 letz 362 }
130    
131 schoenebeck 551
132     // *************** MidiInputDeviceCoreMidi ***************
133     // *
134    
135     MidiInputDeviceCoreMidi::MidiInputDeviceCoreMidi(std::map<String,DeviceCreationParameter*> Parameters, void* pSampler) : MidiInputDevice(Parameters, pSampler)
136 letz 362 {
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 schoenebeck 551 MidiInputDeviceCoreMidi::~MidiInputDeviceCoreMidi()
143 letz 362 {
144     if (hCoreMidiClient) {
145     MIDIClientDispose(hCoreMidiClient);
146 schoenebeck 201 }
147 letz 362 }
148 schoenebeck 551
149 letz 362 MidiInputDeviceCoreMidi::MidiInputPortCoreMidi* MidiInputDeviceCoreMidi::CreateMidiPort() {
150     return new MidiInputPortCoreMidi(this);
151     }
152 schoenebeck 551
153 letz 362 String MidiInputDeviceCoreMidi::Name() {
154 letz 509 return "COREMIDI";
155 letz 362 }
156    
157     String MidiInputDeviceCoreMidi::Driver() {
158     return Name();
159     }
160 schoenebeck 551
161 letz 362 String MidiInputDeviceCoreMidi::Description() {
162     return "Apple CoreMidi";
163     }
164    
165     String MidiInputDeviceCoreMidi::Version() {
166 persson 903 String s = "$Revision: 1.7 $";
167 letz 362 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 schoenebeck 201 }
177    
178 schoenebeck 551
179 schoenebeck 201 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC