/[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 551 - (show annotations) (download)
Tue May 17 18:16:54 2005 UTC (18 years, 11 months ago) by schoenebeck
File size: 6466 byte(s)
* Implemented MIDI program change as general, engine independant solution.
  The program number will determine the sampler channel to which the MIDI
  device will be connected to and the given MIDI channel defines on which
  MIDI channel that sampler channel should listen to. Also the program
  change will disconnect probably established connection from the previous
  program change event.

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

  ViewVC Help
Powered by ViewVC