📄 gnu_javax_sound_midi_dssi_dssisynthesizer.c
字号:
"can't create jack client"); return; } /* Get the jack sample rate, which may be used in default control port value calculations. */ data->sample_rate = jack_get_sample_rate (data->jack_client); data->plugin_handle = (data->desc->LADSPA_Plugin->instantiate)(data->desc->LADSPA_Plugin, data->sample_rate); if (jack_set_process_callback (data->jack_client, process, data) != 0) { JCL_ThrowException (env, "java/io/IOException", "can't set jack process callback"); return; } data->jack_left_output_port = jack_port_register (data->jack_client, "output_left", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); data->jack_right_output_port = jack_port_register (data->jack_client, "output_right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); /* Count the number of controls and audio ouput ports. */ port_count = data->control_count = 0; for (j = 0; j < data->desc->LADSPA_Plugin->PortCount; j++) { LADSPA_PortDescriptor pod = data->desc->LADSPA_Plugin->PortDescriptors[j]; if (LADSPA_IS_PORT_AUDIO(pod) && LADSPA_IS_PORT_OUTPUT(pod)) port_count++; else if (LADSPA_IS_PORT_CONTROL(pod) && LADSPA_IS_PORT_INPUT(pod)) data->control_count++; } /* Allocate the array of control values. */ data->control_values = (LADSPA_Data *) JCL_malloc (env, data->control_count * sizeof (LADSPA_Data)); /* Initialize the MIDI control map. */ memset (data->control_value_map, 0, data->control_count * sizeof(unsigned)); /* Create buffers for each port. */ for (cindex = 0, j = 0; j < data->desc->LADSPA_Plugin->PortCount; j++) { LADSPA_PortDescriptor pod = data->desc->LADSPA_Plugin->PortDescriptors[j]; if (LADSPA_IS_PORT_AUDIO(pod) && LADSPA_IS_PORT_OUTPUT(pod)) { data->left_buffer = (float *) calloc(jack_get_buffer_size(data->jack_client), sizeof(float)); (data->desc->LADSPA_Plugin->connect_port)(data->plugin_handle, j, data->left_buffer); } else if (LADSPA_IS_PORT_CONTROL(pod) && LADSPA_IS_PORT_INPUT(pod)) { /* This is an input control port. Connect it to a properly initialized value in our controller value array. */ (data->desc->LADSPA_Plugin->connect_port) (data->plugin_handle, j, &(data->control_values[cindex])); data->control_values[cindex] = get_port_default (data->desc->LADSPA_Plugin, j, data->sample_rate); /* Set up the mapping between MIDI controllers and this contoller value. */ if (data->desc->get_midi_controller_for_port) { controller = data->desc-> get_midi_controller_for_port(data->plugin_handle, j); if ((controller != DSSI_NONE) && DSSI_IS_CC(controller)) { data->control_value_map[DSSI_CC_NUMBER(controller)] = cindex; data->control_port_map[DSSI_CC_NUMBER(controller)] = j;#ifdef DEBUG_DSSI_PROVIDER printf ("MIDI Controller 0x%x [%s] = %g\n", DSSI_CC_NUMBER(controller), data->desc->LADSPA_Plugin->PortNames[j], data->control_values[cindex]);#endif } } cindex++; } } (data->desc->LADSPA_Plugin->activate)(data->plugin_handle); if (jack_activate (data->jack_client)) JCL_ThrowException (env, "java/io/IOException", "can't activate jack client"); /* Try to connect the synth output to hardware audio ports. */ ports = jack_get_ports (data->jack_client, NULL, NULL, JackPortIsPhysical | JackPortIsInput); if (ports) { if (ports[0] && ports[1]) { /* Don't bother checking return values. Failing is OK. */ jack_connect (data->jack_client, jack_port_name (data->jack_left_output_port), ports[0]); jack_connect (data->jack_client, jack_port_name (data->jack_right_output_port), ports[1]); } free(ports); }}/** * This is called when we receive a new MIDI CONTROL CHANGE message. * Simply stick an appropriate event in the event buffer. This will * get processed in the jack callback function. */JNIEXPORT void JNICALL Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_controlChange_1 (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle, jint channel, jint control, jint value){ dssi_data *data = JLONG_TO_PTR(dssi_data,handle); /* Insert this event in the event buffer. */ snd_seq_event_t *ev = & data->midiEventBuffer[data->midiEventWriteIndex]; /* Set the event value. */ snd_seq_ev_set_controller (ev, channel, control, value); data->midiEventWriteIndex = (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE;}/** * This is called when we receive a new MIDI NOTE ON message. Simply * stick an appropriate event in the event buffer. This will get * processed in the jack callback function. */JNIEXPORT void JNICALL Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_noteOn_1 (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle, jint channel, jint note, jint velocity){ dssi_data *data = JLONG_TO_PTR(dssi_data,handle); /* Insert this event in the event buffer. */ snd_seq_event_t *ev = & data->midiEventBuffer[data->midiEventWriteIndex]; ev->type = SND_SEQ_EVENT_NOTEON; ev->data.control.channel = channel; ev->data.note.note = note; ev->data.note.velocity = velocity; data->midiEventWriteIndex = (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE;}/** * This is called when we receive a new MIDI NOTE OFF message. Simply * stick an appropriate event in the event buffer. This will get * processed in the jack callback function. */JNIEXPORT void JNICALL Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_noteOff_1 (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle, jint channel, jint note, jint velocity){ dssi_data *data = JLONG_TO_PTR(dssi_data,handle); /* Insert this event in the event buffer. */ snd_seq_event_t *ev = & data->midiEventBuffer[data->midiEventWriteIndex]; ev->type = SND_SEQ_EVENT_NOTEOFF; ev->data.control.channel = channel; ev->data.note.note = note; ev->data.note.velocity = velocity; data->midiEventWriteIndex = (data->midiEventWriteIndex + 1) % EVENT_BUFFER_SIZE;}JNIEXPORT void JNICALL Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_setPolyPressure_1 (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle __attribute__((unused)), jint channel __attribute__((unused)), jint note __attribute__((unused)), jint velocity __attribute__((unused))){}JNIEXPORT jint JNICALL Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_getPolyPressure_1 (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle __attribute__((unused)), jint channel __attribute__((unused)), jint note __attribute__((unused))){ return 0;}JNIEXPORT void JNICALL Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_close_1 (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle __attribute__((unused))){}/* FIXME: These next three functions are really inefficient because we're instantiating and cleaning up plugin instances just to query values. */JNIEXPORT jstring JNICALL Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_getProgramName_1 (JNIEnv *env, jclass clazz __attribute__((unused)), jlong handle, jint index){ LADSPA_Handle lhandle; jstring name = (jstring) NULL; dssi_data *data = JLONG_TO_PTR(dssi_data, handle); if (data->desc->get_program == NULL) return NULL; lhandle = (data->desc->LADSPA_Plugin->instantiate)(data->desc->LADSPA_Plugin, 48000); const DSSI_Program_Descriptor *program = (data->desc->get_program)(lhandle, (unsigned long) index); if (program) name = (*env)->NewStringUTF (env, program->Name); (data->desc->LADSPA_Plugin->cleanup)(lhandle); return name;}JNIEXPORT jint JNICALLJava_gnu_javax_sound_midi_dssi_DSSISynthesizer_getProgramBank_1 (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle, jint index){ LADSPA_Handle lhandle; jint result = -1; dssi_data *data = JLONG_TO_PTR(dssi_data, handle); lhandle = (data->desc->LADSPA_Plugin->instantiate)(data->desc->LADSPA_Plugin, 48000); const DSSI_Program_Descriptor *program = (data->desc->get_program)(lhandle, (unsigned long) index); if (program) result = (jint) program->Bank; (data->desc->LADSPA_Plugin->cleanup)(lhandle); return result;}JNIEXPORT jint JNICALL Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_getProgramProgram_1 (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle, jint index){ LADSPA_Handle lhandle; jint result = -1; dssi_data *data = JLONG_TO_PTR(dssi_data, handle); lhandle = (data->desc->LADSPA_Plugin->instantiate)(data->desc->LADSPA_Plugin, 48000); const DSSI_Program_Descriptor *program = (data->desc->get_program)(lhandle, (unsigned long) index); if (program) result = (jint) program->Program; (data->desc->LADSPA_Plugin->cleanup)(lhandle); return result;}JNIEXPORT void JNICALL Java_gnu_javax_sound_midi_dssi_DSSISynthesizer_selectProgram_1 (JNIEnv *env __attribute__((unused)), jclass clazz __attribute__((unused)), jlong handle, jint bank, jint program){ dssi_data *data = JLONG_TO_PTR(dssi_data, handle); (data->desc->select_program)(data->plugin_handle, (unsigned) bank, (unsigned) program);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -