00001
00017 #include "CoreMidiDeviceProvider.h"
00018
00020
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 JNIEXPORT jint JNICALL Java_uk_co_xfactorylibrarians_coremidi4j_CoreMidiDeviceProvider_getNumberOfSources(JNIEnv *env, jobject obj) {
00038
00039 return (jint) MIDIGetNumberOfSources();
00040
00041 }
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 JNIEXPORT jint JNICALL Java_uk_co_xfactorylibrarians_coremidi4j_CoreMidiDeviceProvider_getNumberOfDestinations(JNIEnv *env, jobject obj) {
00058
00059 return (jint) MIDIGetNumberOfDestinations();
00060
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 JNIEXPORT jint JNICALL Java_uk_co_xfactorylibrarians_coremidi4j_CoreMidiDeviceProvider_getSource(JNIEnv *env, jobject obj, jint sourceIndex) {
00081
00082 if ( sourceIndex >= MIDIGetNumberOfSources() ) {
00083
00084 ThrowException(env,CFSTR("MIDIGetSource"),sourceIndex);
00085
00086 }
00087
00088 return MIDIGetSource(sourceIndex);
00089
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 JNIEXPORT jint JNICALL Java_uk_co_xfactorylibrarians_coremidi4j_CoreMidiDeviceProvider_getDestination(JNIEnv *env, jobject obj, jint destinationIndex) {
00110
00111 if ( destinationIndex >= MIDIGetNumberOfDestinations() ) {
00112
00113 ThrowException(env,CFSTR("MIDIGetDestination"), destinationIndex);
00114
00115 }
00116
00117 return MIDIGetDestination(destinationIndex);
00118
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 JNIEXPORT jint JNICALL Java_uk_co_xfactorylibrarians_coremidi4j_CoreMidiDeviceProvider_getUniqueID(JNIEnv *env, jobject obj, jint endPointReference) {
00137
00138 SInt32 uid = 0;
00139
00140 MIDIObjectGetIntegerProperty(endPointReference, kMIDIPropertyUniqueID, &uid);
00141
00142 return uid;
00143
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 JNIEXPORT jobject JNICALL Java_uk_co_xfactorylibrarians_coremidi4j_CoreMidiDeviceProvider_getMidiDeviceInfo(JNIEnv *env, jobject obj, jint endPointReference) {
00162
00163 MIDIDeviceRef deviceReference = NULL;
00164 CFStringRef deviceName = NULL;
00165 CFStringRef deviceManufacturer = NULL;
00166 CFStringRef deviceModel = NULL;
00167 CFStringRef deviceOffline = NULL;
00168 SInt32 deviceUniqueID = 0;
00169 SInt32 deviceDriverVersion = 0;
00170
00171 MIDIEntityRef entityReference = NULL;
00172 CFStringRef entityName = NULL;
00173 CFStringRef entityManufacturer = NULL;
00174 CFStringRef entityModel = NULL;
00175 CFStringRef entityOffline = NULL;
00176 SInt32 entityUniqueID = 0;
00177 SInt32 entityDriverVersion = 0;
00178
00179
00180 CFStringRef endpointName = NULL;
00181 CFStringRef endpointManufacturer = NULL;
00182 CFStringRef endpointModel = NULL;
00183 CFStringRef endpointOffline = NULL;
00184 SInt32 endpointUniqueID = 0;
00185 SInt32 endpointDriverVersion = 0;
00186
00187
00188 jclass javaClass = env->FindClass("uk/co/xfactorylibrarians/coremidi4j/CoreMidiDeviceInfo");
00189 jmethodID constructor = env->GetMethodID(javaClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IILjava/lang/String;IILjava/lang/String;II)V");
00190
00191
00192 MIDIObjectGetStringProperty (endPointReference, kMIDIPropertyName, &endpointName);
00193 MIDIObjectGetStringProperty (endPointReference, kMIDIPropertyModel, &endpointModel);
00194 MIDIObjectGetStringProperty (endPointReference, kMIDIPropertyManufacturer, &endpointManufacturer);
00195 MIDIObjectGetStringProperty (endPointReference, kMIDIPropertyOffline, &endpointOffline);
00196 MIDIObjectGetIntegerProperty(endPointReference, kMIDIPropertyUniqueID, &endpointUniqueID);
00197 MIDIObjectGetIntegerProperty(endPointReference, kMIDIPropertyDriverVersion, &endpointDriverVersion);
00198
00199
00200 MIDIEndpointGetEntity(endPointReference, &entityReference);
00201
00202 MIDIObjectGetStringProperty (entityReference, kMIDIPropertyName, &entityName);
00203 MIDIObjectGetStringProperty (entityReference, kMIDIPropertyModel, &entityModel);
00204 MIDIObjectGetStringProperty (entityReference, kMIDIPropertyManufacturer, &entityManufacturer);
00205 MIDIObjectGetStringProperty (entityReference, kMIDIPropertyOffline, &entityOffline);
00206 MIDIObjectGetIntegerProperty(entityReference, kMIDIPropertyUniqueID, &entityUniqueID);
00207 MIDIObjectGetIntegerProperty(entityReference, kMIDIPropertyDriverVersion, &entityDriverVersion);
00208
00209
00210 MIDIEntityGetDevice(entityReference, &deviceReference);
00211
00212 MIDIObjectGetStringProperty (deviceReference, kMIDIPropertyName, &deviceName);
00213 MIDIObjectGetStringProperty (deviceReference, kMIDIPropertyModel, &deviceModel);
00214 MIDIObjectGetStringProperty (deviceReference, kMIDIPropertyManufacturer, &deviceManufacturer);
00215 MIDIObjectGetStringProperty (deviceReference, kMIDIPropertyOffline, &deviceOffline);
00216 MIDIObjectGetIntegerProperty(deviceReference, kMIDIPropertyUniqueID, &deviceUniqueID);
00217 MIDIObjectGetIntegerProperty(deviceReference, kMIDIPropertyDriverVersion, &deviceDriverVersion);
00218
00219 long numberOfEntities = MIDIDeviceGetNumberOfEntities(deviceReference);
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 CFMutableStringRef buildName = CFStringCreateMutable(NULL, 0);
00253 CFStringRef deviceInfoName;
00254
00255 if ( buildName != NULL ) {
00256
00257 CFStringAppend(buildName, deviceName);
00258
00259 if ( numberOfEntities > 1 ) {
00260
00261 CFStringAppend(buildName, CFSTR(" "));
00262 CFStringAppend(buildName, entityName);
00263
00264 }
00265
00266
00267 deviceInfoName = CFStringCreateCopy(NULL, buildName);
00268
00269
00270 CFRelease(buildName);
00271
00272 }
00273
00274 const char *deviceInfoNamePtr = CFStringGetCStringPtr ( deviceInfoName, CFStringGetSystemEncoding() );
00275 const char *deviceInfoManufacturerPtr = CFStringGetCStringPtr ( deviceManufacturer, CFStringGetSystemEncoding() );
00276 const char *deviceInfoDescriptionPtr = CFStringGetCStringPtr ( deviceModel, CFStringGetSystemEncoding() );
00277
00278 const char *deviceNamePtr = CFStringGetCStringPtr ( deviceName, CFStringGetSystemEncoding() );
00279 const char *entityNamePtr = CFStringGetCStringPtr ( entityName, CFStringGetSystemEncoding() );
00280 const char *endPointNamePtr = CFStringGetCStringPtr ( endpointName, CFStringGetSystemEncoding() );
00281
00282
00283 const char *deviceInfoVersion = "Unknown Version";
00284
00285
00286 jobject info = env->NewObject(javaClass,
00287 constructor,
00288 env->NewStringUTF(( deviceInfoNamePtr != NULL ) ? deviceInfoNamePtr : "** Internal Error getting Device Name!"),
00289 env->NewStringUTF(( deviceInfoManufacturerPtr != NULL ) ? deviceInfoManufacturerPtr : "Unknown Manufacturer"),
00290 env->NewStringUTF(( deviceInfoDescriptionPtr != NULL ) ? deviceInfoDescriptionPtr : "Unknown Description"),
00291 env->NewStringUTF(deviceInfoVersion),
00292 env->NewStringUTF(deviceNamePtr),
00293 deviceReference,
00294 deviceUniqueID,
00295 env->NewStringUTF(entityNamePtr),
00296 entityReference,
00297 entityUniqueID,
00298 env->NewStringUTF(endPointNamePtr),
00299 endPointReference,
00300 endpointUniqueID);
00301
00302 return info;
00303
00304 }
00305