示例#1
0
/*
 * fluid_midishare_keyoff_task
 */
static void fluid_midishare_keyoff_task (long date, short ref, long a1, long a2, long a3)
{
    fluid_midishare_midi_driver_t* dev = (fluid_midishare_midi_driver_t*)MidiGetInfo(ref);
    fluid_midi_event_t new_event;
    MidiEvPtr e =(MidiEvPtr)a1;

    fluid_midi_event_set_type(&new_event, NOTE_OFF);
    fluid_midi_event_set_channel(&new_event, Chan(e));
    fluid_midi_event_set_pitch(&new_event, Pitch(e));
    fluid_midi_event_set_velocity(&new_event, Vel(e)); /* release vel */

    /* and send it on its way to the router */
    (*dev->driver.handler)(dev->driver.data, &new_event);

    MidiFreeEv(e);
}
/*
 * Class:     org_tritonus_midi_device_fluidsynth_FluidSynthesizer
 * Method:    nReceive
 * Signature: (IIII)V
 */
JNIEXPORT void JNICALL Java_org_tritonus_midi_device_fluidsynth_FluidSynthesizer_nReceive
(JNIEnv *env, jobject obj, jint command, jint channel, jint data1, jint data2)
{
	fluid_midi_event_t* event;
	fluid_synth_t* synth = get_synth(env, obj);

#ifdef VARIADIC_MACROS
	out("nReceive: synth: %p, values: %x %d %d %d\n", synth, (int) command, (int) channel, (int) data1, (int) data2);
#else
	if (debug_flag)
	{
		fprintf(debug_file, "synth: %p, values: %x %d %d %d\n", synth, (int) command, (int) channel, (int) data1, (int) data2);
		fflush(debug_file);
	}
#endif
	if (synth)
	{
		event = new_fluid_midi_event();
		if (!event)
		{
			printf("failed to instantiate fluid_midi_event_t\n");
			return;
		}
		//printf("2"); fflush(stdout);
		fluid_midi_event_set_type(event, command);
		fluid_midi_event_set_channel(event, channel);
		fluid_midi_event_set_key(event, data1);
		fluid_midi_event_set_velocity(event, data2);
		//printf("3"); fflush(stdout);
		/*printf("values2: %d %d %d %d\n",
		fluid_midi_event_get_type(event),
		fluid_midi_event_get_channel(event),
		fluid_midi_event_get_key(event),
		fluid_midi_event_get_velocity(event));
		fflush(stdout);
	*/
		fluid_synth_handle_midi_event(synth, event);
		//printf("4"); fflush(stdout);
		delete_fluid_midi_event(event);
		//printf("5\n"); fflush(stdout);
	}
}
示例#3
0
/*
 * fluid_midishare_midi_driver_receive
 */
static void fluid_midishare_midi_driver_receive(short ref)
{
    fluid_midishare_midi_driver_t* dev = (fluid_midishare_midi_driver_t*)MidiGetInfo(ref);
    fluid_midi_event_t new_event;
    MidiEvPtr e;
    int count, i;

    while ((e = MidiGetEv (ref)))
    {
        switch (EvType (e))
        {
        case typeNote:
            /* Copy the data to fluid_midi_event_t */
            fluid_midi_event_set_type(&new_event, NOTE_ON);
            fluid_midi_event_set_channel(&new_event, Chan(e));
            fluid_midi_event_set_pitch(&new_event, Pitch(e));
            fluid_midi_event_set_velocity(&new_event, Vel(e));

            /* and send it on its way to the router */
            (*dev->driver.handler)(dev->driver.data, &new_event);

#if defined(MACINTOSH) && defined(MACOS9)
            MidiTask(dev->upp_task_ptr, MidiGetTime()+Dur(e), ref, (long)e, 0, 0);
#else
            MidiTask(fluid_midishare_keyoff_task, MidiGetTime()+Dur(e), ref, (long)e, 0, 0);
#endif

            /* e gets freed in fluid_midishare_keyoff_task */
            continue;

        case typeKeyOn:
            /* Copy the data to fluid_midi_event_t */
            fluid_midi_event_set_type(&new_event, NOTE_ON);
            fluid_midi_event_set_channel(&new_event, Chan(e));
            fluid_midi_event_set_pitch(&new_event, Pitch(e));
            fluid_midi_event_set_velocity(&new_event, Vel(e));
            break;

        case typeKeyOff:
            /* Copy the data to fluid_midi_event_t */
            fluid_midi_event_set_type(&new_event, NOTE_OFF);
            fluid_midi_event_set_channel(&new_event, Chan(e));
            fluid_midi_event_set_pitch(&new_event, Pitch(e));
            fluid_midi_event_set_velocity(&new_event, Vel(e)); /* release vel */
            break;

        case typeCtrlChange:
            /* Copy the data to fluid_midi_event_t */
            fluid_midi_event_set_type(&new_event, CONTROL_CHANGE);
            fluid_midi_event_set_channel(&new_event, Chan(e));
            fluid_midi_event_set_control(&new_event, MidiGetField(e,0));
            fluid_midi_event_set_value(&new_event, MidiGetField(e,1));
            break;

        case typeProgChange:
            /* Copy the data to fluid_midi_event_t */
            fluid_midi_event_set_type(&new_event, PROGRAM_CHANGE);
            fluid_midi_event_set_channel(&new_event, Chan(e));
            fluid_midi_event_set_program(&new_event, MidiGetField(e,0));
            break;

        case typePitchWheel:
            /* Copy the data to fluid_midi_event_t */
            fluid_midi_event_set_type(&new_event, PITCH_BEND);
            fluid_midi_event_set_channel(&new_event, Chan(e));
            fluid_midi_event_set_value(&new_event, ((MidiGetField(e,0)
                                                    + (MidiGetField(e,1) << 7))
                                                    - 8192));
            break;

        case typeSysEx:
            count = MidiCountFields (e);

            /* Discard empty or too large SYSEX messages */
            if (count == 0 || count > FLUID_MIDI_PARSER_MAX_DATA_SIZE)
            {
                MidiFreeEv (e);
                continue;
            }

            /* Copy SYSEX data, one byte at a time */
            for (i = 0; i < count; i++)
                dev->sysexbuf[i] = MidiGetField (e, i);

            fluid_midi_event_set_sysex (&new_event, dev->sysexbuf, count, FALSE);
            break;

        default:
            MidiFreeEv (e);
            continue;
        }

        MidiFreeEv (e);

        /* Send the MIDI event */
        (*dev->driver.handler)(dev->driver.data, &new_event);
    }
}