Example #1
0
void midi_thread(void *data){
	snd_seq_t *seq_handle;
	int npfd;
	struct pollfd *pfd;

	seq_handle = open_seq();
	npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
	pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd));
	snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN);
	while (1) {
		if (poll(pfd, npfd, 100000) > 0) {
			midi_action(seq_handle);
		}  
	}
}
Example #2
0
int main(int argc, char *argv[]) {

  snd_seq_t *seq_handle;
  int npfd;
  struct pollfd *pfd;

  seq_handle = open_seq();
  npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
  pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd));
  snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN);

	fprintf(stderr, "COMMAND:CHANNEL:NOTE\nCommands are described on http://www.ec.vanderbilt.edu/computermusic/musc216site/MIDI.Commands.html\n\n");
  while (1) {
    if (poll(pfd, npfd, 100000) > 0) {
      midi_action(seq_handle);
    }
  }
}
Example #3
0
int main (int argc, char *argv[])
{

	snd_seq_t *seq_handle;
	int npfd;
	struct pollfd *pfd;

	seq_handle = open_seq();
	npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
	pfd = malloc(npfd * sizeof(*pfd));
	snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN);

	if (argc >= 2) {
		snd_seq_addr_t addr;
		if (snd_seq_parse_address(seq_handle, &addr, argv[1]) == 0) {
			if (snd_seq_connect_from(seq_handle, portid, addr.client, addr.port) == 0) {
				printf("Connected to %s\n", argv[1]);
			}
		}
	}

	int i;
	for (i=2; i<argc; i++)
		channels |= 1<<(atoi(argv[i])-1);

	OLRenderParams params;

	memset(&params, 0, sizeof params);
	params.rate = 48000;
	params.on_speed = 2.0/50.0;
	params.off_speed = 2.0/35.0;
	params.start_wait = 6;
	params.start_dwell = 1;
	params.curve_dwell = 0;
	params.corner_dwell = 0;
	params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg
	params.end_dwell = 0;
	params.end_wait = 7;
	params.flatness = 0.00001;
	params.snap = 1/100000.0;
	params.render_flags = RENDER_GRAYSCALE;

	if(olInit(3, 30000) < 0)
		return 1;

	olSetRenderParams(&params);

	float time = 0;
	float ftime;

	int frames = 0;

	float nps = 0;
	avgnotes = 5;
	
	while(1) {
		olLoadIdentity();

		int drawn = draw();
		if (drawn < 2)
			draw();

		ftime = olRenderFrame(100);

		float t = powf(0.3, ftime);
		avgnotes = avgnotes * t + (nps+2) * (1.0f-t);

		animate(ftime);

		int notes = 0;
		if (poll(pfd, npfd, 0) > 0)
			notes = midi_action(seq_handle);

		int pnotes = (notes+2)/3;

		nps = pnotes / ftime * 1.2;

		frames++;
		time += ftime;
		printf("Frame time: %f, Avg FPS:%f, Cur FPS:%f, %d, nps:%3d, avgnotes:%f\n", ftime, frames/time, 1/ftime, notes, (int)nps, avgnotes);
	}

	olShutdown();
	exit (0);
}