/[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 509 - (hide annotations) (download)
Tue May 3 16:55:28 2005 UTC (18 years, 11 months ago) by letz
File size: 6473 byte(s)
Correct Name method

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

  ViewVC Help
Powered by ViewVC