Пример #1
0
void SndioMidiDriver::open()
{
	char midiDevice[32];

	INFOLOG("SndioMidiDriver::open");

	snprintf(midiDevice, 32, (Preferences::get_instance()->m_sMidiPortName).toAscii());

	if (strncmp(midiDevice, "", 1) == 0 ||
	    strncmp(midiDevice, "None", 5) == 0 ||
	    strncmp(midiDevice, "default", 8) == 0)
		hdl = mio_open(NULL, MIO_IN, 0);
	else
		hdl = mio_open(midiDevice, MIO_IN, 0);

	if (!hdl) {
		ERRORLOG("mio_open failed");
		m_bRunning = false;
		return;
	}
	m_bRunning = true;

	pthread_attr_t attr;
	pthread_attr_init(&attr);
	pthread_create(&SndioMidiDriverThread, &attr, SndioMidiDriver_thread, ( void* )this);
}
Пример #2
0
fluid_midi_driver_t *
new_fluid_sndio_midi_driver(fluid_settings_t *settings,
			       handle_midi_event_func_t handler, void *data)
{
  int err;
  fluid_sndio_midi_driver_t *dev;
  char *device;

  /* not much use doing anything */
  if (handler == NULL) {
    FLUID_LOG(FLUID_ERR, "Invalid argument");
    return NULL;
  }

  /* allocate the device */
  dev = FLUID_NEW(fluid_sndio_midi_driver_t);
  if (dev == NULL) {
    FLUID_LOG(FLUID_ERR, "Out of memory");
    return NULL;
  }
  FLUID_MEMSET(dev, 0, sizeof(fluid_sndio_midi_driver_t));
  dev->hdl = NULL;

  dev->driver.handler = handler;
  dev->driver.data = data;

  /* allocate one event to store the input data */
  dev->parser = new_fluid_midi_parser();
  if (dev->parser == NULL) {
    FLUID_LOG(FLUID_ERR, "Out of memory");
    goto error_recovery;
  }

  /* get the device name. if none is specified, use the default device. */
  if (!fluid_settings_dupstr(settings, "midi.sndio.device", &device)) {
	device = NULL;
  }

  /* open the default hardware device. only use midi in. */
  dev->hdl = mio_open(device, MIO_IN, 0);
  if (dev->hdl == NULL) {
    FLUID_LOG(FLUID_ERR, "Couldn't open sndio midi device");
    goto error_recovery;
  }

  dev->status = FLUID_MIDI_READY;

  err = pthread_create(&dev->thread, NULL, fluid_sndio_midi_run, (void *)dev);
  if (err) {
    FLUID_LOG(FLUID_PANIC, "Couldn't create the midi thread.");
    goto error_recovery;
  }
  return (fluid_midi_driver_t *) dev;

 error_recovery:
  delete_fluid_sndio_midi_driver((fluid_midi_driver_t *)dev);
  return NULL;
}
Пример #3
0
void prog_load(Prog* prog, const char* cmdpipe, const char* filename)
{
   int   bufsize = BUF_EXT;
   char* buf     = malloc((size_t)bufsize);
   MFP*  fp;
   char* s;
   int   lineno  = 1;
   char  newname [1024];
   char* temp;
   char* myfilename;
   
   assert(prog     != NULL);
   assert(filename != NULL);
   assert(buf      != NULL);
   assert(filename != NULL);

   if (cmdpipe == NULL)
      myfilename = strdup(filename);
   else
   {
      myfilename = malloc(strlen(filename) + strlen(cmdpipe) + 1024);
      
      sprintf(&myfilename[1], cmdpipe, filename);
      myfilename[0] = '#';
   }
   if (NULL == (fp = mio_open(myfilename, ".zpl")))
      zpl_exit(EXIT_FAILURE);

   if (verbose)
      printf("Reading %s\n", myfilename);
   
   while((s = get_line(&buf, &bufsize, fp, &lineno)) != NULL)
   {
      assert(!isspace(*s));

      /* This could happen if we have a ;; somewhere.
       */
      if (*s == '\0')
         continue;

      if (1 == sscanf(s, "include \"%1023[^\"]\"", newname))
      {
         temp = malloc(strlen(filename) + strlen(newname) + 2);
         prog_load(prog, cmdpipe, make_pathname(temp, filename, newname));
         free(temp);
      }
      else
      { 
         add_stmt(prog, filename, lineno, s);
      }
   }
   mio_close(fp);
   free(myfilename);
   free(buf);
}
Пример #4
0
MidiSndio::MidiSndio( void ) :
	MidiClientRaw(),
	m_quit( false )
{
	QString dev = probeDevice();

	if (dev == "")
	{
		m_hdl = mio_open( NULL, MIO_IN | MIO_OUT, 0 );
	}
	else
	{
		m_hdl = mio_open( dev.toLatin1().constData(), MIO_IN | MIO_OUT, 0 );
	}

	if( m_hdl == NULL )
	{
		printf( "sndio: failed opening sndio midi device\n" );
		return;
	}

	start( QThread::LowPriority );
}
Пример #5
0
static void zero_words(size_t n)
{
  mio_handle_t mio;
  size_t i;

  if (mio_open(&mio, 0x80001000, 0x1000))
  {
    printf("unable to zero_words\n");
    return ;
  }

  for (i = 0; i != n; ++i)
    mio_write_uint32(&mio, i * sizeof(uint32_t), 0);

  mio_close(&mio);
}
Пример #6
0
static int pwmss_open(mio_handle_t* mio, unsigned int i)
{
  /* i the pwmss id, in [0:2] */

  const uintptr_t addr[] =
  {
    PWMSS0_MIO_ADDR,
    PWMSS1_MIO_ADDR,
    PWMSS2_MIO_ADDR
  };

  /* enable pwmss clocking */
  if (cm_per_enable_pwmss(i)) return -1;

  if (mio_open(mio, addr[i], PWMSS_MIO_SIZE)) return -1;

  return 0;
}
Пример #7
0
static int cm_per_enable_pwmss(size_t i)
{
  /* enable clocking of the pwmss[i] */

  static const size_t off[] =
  {
    CM_PER_EPWMSS0_CLKCTRL,
    CM_PER_EPWMSS1_CLKCTRL,
    CM_PER_EPWMSS2_CLKCTRL
  };

  mio_handle_t mio;

  if (mio_open(&mio, CM_PER_MIO_ADDR, CM_PER_MIO_SIZE)) return -1;
  mio_write_uint32(&mio, off[i], 2);
  mio_close(&mio);

  return 0;
}
Пример #8
0
int
main(int argc, char **argv)
{
	int ch;
	int example = 0;
	int gmreset = 0;
	char *file = NULL;
	FILE *f;
	const char *errstr;
	struct sigaction sa;
	struct itimerval it;

	while ((ch = getopt(argc, argv, "?d:f:glmqt:vx")) != -1) {
		switch (ch) {
		case 'f':
			file = optarg;
			break;
		case 'g':
			gmreset = 1;
			break;
		case 'm':
			showmeta = 1;
			break;
		case 'q':
			play = 0;
			break;
		case 't':
			tempo = 60 * 1000000 / 
			    strtonum(optarg, 40, 240, &errstr);
			if (errstr)
				errx(1, "tempo is %s: %s", errstr, optarg);
			break;
		case 'v':
			verbose++;
			break;
		case 'x':
			example = 1;
			break;
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;
    
	hdl = mio_open(file, MIO_OUT, 0);
	if (hdl == NULL)
		errx(1, "failed to open MIDI output");
	if (gmreset)
		midireset();

	sa.sa_flags = SA_RESTART;
	sa.sa_handler = sigalrm;
	sigfillset(&sa.sa_mask);
	if (sigaction(SIGALRM, &sa, NULL) < 0)
		err(1, "sigaction");
	it.it_interval.tv_sec = it.it_value.tv_sec = 0;
	it.it_interval.tv_usec = it.it_value.tv_usec = 1000;
	if (setitimer(ITIMER_REAL, &it, NULL) < 0)
		err(1, "setitimer");

	if (example)
		playdata(sample, sizeof sample, "<Gubben Noa>");
	else if (argc == 0)
		playfile(stdin, "<stdin>");
	else
		while (argc--) {
			f = fopen(*argv, "r");
			if (f == NULL)
				err(1, "%s", *argv);
			else {
				playfile(f, *argv);
				fclose(f);
			}
			argv++;
		}

	exit(0);
}