⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gnu_javax_sound_midi_alsa_alsaportdevice.c

📁 gcc的组建
💻 C
字号:
/* gnu_javax_sound_midi_alsa_AlsaPortDevice.c - Native support   Copyright (C) 2005    Free Software Foundation, Inc.   This file is part of GNU Classpath.   GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.   GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.   You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.   Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.   As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */#include <config.h>#include <gnu_javax_sound_midi_alsa_AlsaPortDevice.h>#include <unistd.h>#include <alsa/asoundlib.h>JNIEXPORT void JNICALLJava_gnu_javax_sound_midi_alsa_AlsaPortDevice_run_1receiver_1thread_1  (JNIEnv *env, jobject this __attribute__((unused)),    jlong client, jlong port, jobject receiver){  int rc;  snd_seq_port_info_t *pinfo, *sinfo;  snd_seq_port_subscribe_t *subs;  snd_seq_addr_t sender, dest;  snd_seq_t *seq;  snd_seq_port_info_alloca (&pinfo);  snd_seq_port_info_alloca (&sinfo);  snd_seq_port_subscribe_alloca (&subs);  rc = snd_seq_open (&seq, "default", SND_SEQ_OPEN_DUPLEX, SND_SEQ_NONBLOCK);  snd_seq_port_info_set_capability (pinfo, SND_SEQ_PORT_CAP_WRITE);  snd_seq_port_info_set_type (pinfo, SND_SEQ_PORT_TYPE_MIDI_GENERIC);  rc = snd_seq_create_port (seq, pinfo);  sender.client = (int) client;  sender.port = (int) port;  dest.client = snd_seq_port_info_get_client(pinfo);  dest.port = snd_seq_port_info_get_port(pinfo);  snd_seq_port_subscribe_set_sender (subs, &sender);  snd_seq_port_subscribe_set_dest (subs, &dest);  rc = snd_seq_subscribe_port(seq, subs);  {    int npfd;    struct pollfd *pfd;    jclass smcls, rcls;    jmethodID sminit, rsend;    jbyteArray mba;    jbyte *ba;    jobject msg;    jlong jtimestamp;    npfd = snd_seq_poll_descriptors_count (seq, POLLIN);    pfd = (struct pollfd *) alloca (npfd * sizeof (struct pollfd));    snd_seq_poll_descriptors (seq, pfd, npfd, POLLIN);    smcls = (*env)->FindClass(env, "javax/sound/midi/ShortMessage");    sminit = (*env)->GetMethodID(env, smcls, "<init>", "([B)V");    rcls = (*env)->FindClass(env, "javax/sound/midi/Receiver");    rsend = (*env)->GetMethodID(env, rcls, "send", "(Ljavax/sound/midi/MidiMessage;J)V");    while (1)      {	if (poll (pfd, npfd, 100000) > 0)	  {	    snd_seq_event_t *ev;	    	    do	      {		snd_seq_event_input (seq, &ev);		if ((ev->flags & SND_SEQ_TIME_STAMP_MASK) == SND_SEQ_TIME_STAMP_TICK)		  jtimestamp = (jlong) ev->time.tick;		else		  jtimestamp = (jlong) ev->time.time.tv_sec * (jlong) 1000000000 		    + (jlong) ev->time.time.tv_nsec;		switch (ev->type)		  {		  case SND_SEQ_EVENT_NOTEON:		    mba = (*env)->NewByteArray (env, 3);		    ba = (*env)->GetByteArrayElements (env, mba, 0);		    ba[0] = 0x90 + ev->data.control.channel;		    ba[1] = ev->data.note.note;		    ba[2] = ev->data.note.velocity;		    (*env)->ReleaseByteArrayElements (env, mba, ba, 0);		    msg = (*env)->NewObject(env, smcls, sminit, mba);		    (*env)->CallObjectMethod(env, receiver, 					     rsend, msg, jtimestamp);		    break;		    		  case SND_SEQ_EVENT_CONTROLLER:		    mba = (*env)->NewByteArray (env, 3);		    ba = (*env)->GetByteArrayElements (env, mba, 0);		    ba[0] = 0xB0 + ev->data.control.channel;		    ba[1] = ev->data.control.param;		    ba[2] = ev->data.control.value;		    (*env)->ReleaseByteArrayElements (env, mba, ba, 0);		    msg = (*env)->NewObject(env, smcls, sminit, mba);		    (*env)->CallObjectMethod(env, receiver, 					     rsend, msg, jtimestamp);		    break;		  default:		    printf ("UNKNOWN EVENT 0x%x\n", ev->type);		    break;		  }		snd_seq_free_event(ev);	      }	    while (snd_seq_event_input_pending (seq, 0) > 0);	  }      }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -