Пример #1
0
static int
mpu401_intr(struct mpu401 *m)
{
#define MPU_INTR_BUF	16
	MIDI_TYPE b[MPU_INTR_BUF];
	int i;
	int s;

/*
	printf("mpu401_intr\n");
*/
#define RXRDY(m) ( (STATUS(m) & MPU_INPUTBUSY) == 0)
#define TXRDY(m) ( (STATUS(m) & MPU_OUTPUTBUSY) == 0)
#if 0
#define D(x,l) printf("mpu401_intr %d %x %s %s\n",l, x, x&MPU_INPUTBUSY?"RX":"", x&MPU_OUTPUTBUSY?"TX":"")
#else
#define D(x,l)
#endif
	i = 0;
	s = STATUS(m);
	D(s, 1);
	while ((s & MPU_INPUTBUSY) == 0 && i < MPU_INTR_BUF) {
		b[i] = READ(m);
/*
		printf("mpu401_intr in i %d d %d\n", i, b[i]);
*/
		i++;
		s = STATUS(m);
	}
	if (i)
		midi_in(m->mid, b, i);
	i = 0;
	while (!(s & MPU_OUTPUTBUSY) && i < MPU_INTR_BUF) {
		if (midi_out(m->mid, b, 1)) {
/*
			printf("mpu401_intr out i %d d %d\n", i, b[0]);
*/

			WRITE(m, *b);
		} else {
/*
			printf("mpu401_intr write: no output\n");
*/
			return 0;
		}
		i++;
		/* DELAY(100); */
		s = STATUS(m);
	}

	if ((m->flags & M_TXEN) && (m->si)) {
		callout_reset(&m->timer, 1, mpu401_timeout, m);
	}
	return (m->flags & M_TXEN) == M_TXEN;
}
Пример #2
0
void eof_midi_play_note_ex(int note, unsigned char channel, unsigned char patch)
{
	unsigned char SET_PATCH_DATA[2] = {0xC0|channel, 28}; 		// 28 = Electric Guitar (clean)
	unsigned char NOTE_ON_DATA[3] = {0x90|channel, 0x0, 127};	//Data sequence for a Note On, channel 1, Note 0
	unsigned char NOTE_OFF_DATA[3] = {0x80|channel, 0x0, 127};	//Data sequence for a Note Off, channel 1, Note 0
	static unsigned char lastnote[16] = {0};					//Remembers the last note that was played on each channel, so it can be turned off
	static unsigned char lastnotedefined[16] = {0};
	static unsigned char patches[16] = {0};	//The last instrument number played on each of the 16 usable channels, is set to nonzero after the instrument is set

	if(midi_driver == NULL)
	{	//Ensure Allegro's MIDI driver is loaded
		return;
	}
	if(channel > 15)
	{	//Bounds check
		channel = 15;
	}
	if(patch |= patches[channel])
	{	//If the instrument number needs to be changed for this channel
		SET_PATCH_DATA[1] = patch;
		midi_out(SET_PATCH_DATA, 2);
		patches[channel] = patch;
	}

	if(note < EOF_MAX_VOCAL_TONES)
	{
		NOTE_ON_DATA[1] = note;	//Alter the data sequence to be the appropriate note number
		if(lastnotedefined[channel])
		{
			NOTE_OFF_DATA[1] = lastnote[channel];
			midi_out(NOTE_OFF_DATA, 3);	//Turn off the last note that was played
		}
		midi_out(NOTE_ON_DATA, 3);	//Turn on this note
		lastnote[channel] = note;
		lastnotedefined[channel] = 1;
	}
}
Пример #3
0
//=======================================================
// メインループ関数
//=======================================================
void MainLoop(void)
{
	ARUint8          *image;			// カメラキャプチャ画像
	ARMarkerInfo     *marker_info;		// マーカ情報
	int              marker_num;		// 検出されたマーカの数
	int              i, j, k;

	// カメラ画像の取得
	if( (image = (ARUint8 *)arVideoGetImage()) == NULL ){
		arUtilSleep( 2 );
		return;
	}
	if( count == 0 ) arUtilTimerReset();
	count++;

	// カメラ画像の描画
	argDrawMode2D();
	argDispImage( image, 0, 0 );


	// マーカの検出と認識
	if( arDetectMarker( image, thresh, &marker_info, &marker_num ) < 0 ){
		Cleanup();
		exit(0);
	}

	// 次の画像のキャプチャ指示
	arVideoCapNext();

	// 3Dオブジェクトを描画するための準備
	argDrawMode3D();
	argDraw3dCamera( 0, 0 );
	glClearDepth(1.0);					// デプスバッファの消去値
	glClear( GL_DEPTH_BUFFER_BIT );		// デプスバッファの初期化

	if(movex[0]!=0 && movex[3]!=0 && movex[7]!=0){
		rmove++;
		
		if(rmove!=0){
			Drawnashi( marker[3].mark_id, marker[3].patt_trans);
		}
		if(rmove>40.0){
			rmove=0.0;
			for(int i=0;i<MARK_NUM;i++){
				movex[i]=0;
			}
		}
	}else{
		// マーカの一致度の比較
		for( i=0; i<MARK_NUM; i++ ){
			k = -1;
			for( j=0; j<marker_num; j++ ){
				if( marker[i].patt_id == marker_info[j].id ){
					if( k == -1 ) k = j;
					else if( marker_info[k].cf < marker_info[j].cf ) k = j;
				}
			}

			// マーカーが見つからなかったとき
			if( k == -1 ){
				if(marker[i].visible != 0){
					midi_out(i+1);
					midi_stop(i+1);
					movex[i]=1;
					marker[i].visible = 0;
				}else if(movex[i]!=0){
					DrawObject( marker[i].mark_id, marker[i].patt_trans,i );
				}
			}else{
				// 座標変換行列を取得
				if( marker[i].visible == 0 ) {
					// 1フレームを使ってマーカの位置・姿勢(座標変換行列)の計算
					arGetTransMat( &marker_info[k], marker[i].patt_center, marker[i].patt_width, marker[i].patt_trans );    //初回の認識ではarGetTransMatを2回目以降ではarGetTransMatContを使うと安定するらしい
					marker[i].visible = 1;

				} else {
					// 前のフレームを使ってマーカの位置・姿勢(座標変換行列)の計算
					arGetTransMatCont( &marker_info[k], marker[i].patt_trans, marker[i].patt_center, marker[i].patt_width, marker[i].patt_trans );
				}

				// 3Dオブジェクトの描画
				if(movex[i]!=0){
					DrawObject( marker[i].mark_id, marker[i].patt_trans,i );
				}
			}
			if(movex[i]>=40.0) movex[i]=0;
			if(movex[i]!=0) movex[i]++;
		}
	}
	// バッファの内容を画面に表示
	argSwapBuffers();
}