6
#include "org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem.h"
12
JNIEXPORT jlong JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_malloc(JNIEnv* env, jobject obj)
16
midi_handle_t *handle = (midi_handle_t *) malloc( sizeof(midi_handle_t) );
19
memcpy(&ptr, &handle, sizeof( handle ));
24
JNIEXPORT void JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_free(JNIEnv* env, jobject obj, jlong ptr)
26
midi_handle_t *handle = NULL;
27
memcpy(&handle, &ptr, sizeof(handle));
33
JNIEXPORT void JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_findPorts(JNIEnv* env, jobject obj, jlong ptr)
35
midi_handle_t *handle = NULL;
36
memcpy(&handle, &ptr, sizeof(handle));
40
count = midiOutGetNumDevs();
41
for (i = 0; i < count; i++){
42
if (midiOutGetDevCaps(i, &moc, sizeof(MIDIOUTCAPS)) == MMSYSERR_NOERROR){
43
int srcLen = strlen( moc.szPname );
44
int dstLen = MultiByteToWideChar( CP_ACP, 0, (LPCSTR)moc.szPname, srcLen, NULL, 0 );
45
wchar_t* dstBuffer = malloc( (dstLen * 2) + 1 );
46
MultiByteToWideChar( CP_ACP, 0, (LPCSTR)moc.szPname, srcLen,(LPWSTR)dstBuffer, dstLen );
48
//Add a new MidiDevice to the java class
50
jstring name = (*env)->NewString( env, (jchar*)dstBuffer, dstLen );
51
jclass cl = (*env)->GetObjectClass(env, obj);
52
jmethodID mid = (*env)->GetMethodID(env, cl, "addPort", "(Ljava/lang/String;I)V");
54
(*env)->CallVoidMethod(env, obj, mid, name, device);
62
JNIEXPORT void JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_openPort(JNIEnv* env, jobject obj, jlong ptr, jint device)
64
midi_handle_t *handle = NULL;
65
memcpy(&handle, &ptr, sizeof(handle));
66
if(handle != NULL && handle->out == NULL){
67
handle->out = (HMIDIOUT *)malloc( sizeof(HMIDIOUT) );
68
if ( midiOutOpen(handle->out, (UINT)device, 0, 0, CALLBACK_WINDOW) != MMSYSERR_NOERROR ){
75
JNIEXPORT void JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_closePort(JNIEnv* env, jobject obj, jlong ptr)
77
midi_handle_t *handle = NULL;
78
memcpy(&handle, &ptr, sizeof(handle));
79
if(handle != NULL && handle->out != NULL){
80
midiOutClose(*handle->out);
86
JNIEXPORT void JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_noteOn(JNIEnv* env, jobject ojb, jlong ptr, jint channel, jint note, jint velocity)
88
midi_handle_t *handle = NULL;
89
memcpy(&handle, &ptr, sizeof(handle));
90
if(handle != NULL && handle->out != NULL){
91
midiOutShortMsg(*handle->out, ( ( 0x90 | channel ) | ( note << 8) | ( velocity << 16) ) );
95
JNIEXPORT void JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_noteOff(JNIEnv* env, jobject ojb, jlong ptr, jint channel, jint note, jint velocity)
97
midi_handle_t *handle = NULL;
98
memcpy(&handle, &ptr, sizeof(handle));
99
if(handle != NULL && handle->out != NULL){
100
midiOutShortMsg(*handle->out, ( ( 0x80 | channel ) | ( note << 8) | ( velocity << 16) ) );
104
JNIEXPORT void JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_programChange(JNIEnv* env, jobject ojb, jlong ptr, jint channel, jint program)
106
midi_handle_t *handle = NULL;
107
memcpy(&handle, &ptr, sizeof(handle));
108
if(handle != NULL && handle->out != NULL){
109
midiOutShortMsg(*handle->out, ( ( 0xC0 | channel ) | ( program << 8) ) );
113
JNIEXPORT void JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_controlChange(JNIEnv* env, jobject ojb, jlong ptr, jint channel, jint control, jint value)
115
midi_handle_t *handle = NULL;
116
memcpy(&handle, &ptr, sizeof(handle));
117
if(handle != NULL && handle->out != NULL){
118
midiOutShortMsg(*handle->out, ( ( 0xB0 | channel ) | ( control << 8) | ( value << 16) ) );
122
JNIEXPORT void JNICALL Java_org_herac_tuxguitar_player_impl_midiport_winmm_MidiSystem_pitchBend(JNIEnv* env, jobject ojb, jlong ptr, jint channel, jint value)
124
midi_handle_t *handle = NULL;
125
memcpy(&handle, &ptr, sizeof(handle));
126
if(handle != NULL && handle->out != NULL){
127
midiOutShortMsg(*handle->out, ( ( 0xE0 | channel ) | ( (value * 128 * 2) << 8 ) ) );