Exemplo n.º 1
0
bool Midi2UdpThread::initSeq()
{
	if(snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0) < 0) {
    	printf("midi2udp: Error opening ALSA sequencer.\n");
    	return false;
  	}
	
	snd_seq_set_client_name(seq_handle, "DSMIDIWIFI MIDI2UDP");
	
	char portname[64] = "DSMIDIWIFI MIDI2UDP IN";
	
	int res = midi_in_port = snd_seq_create_simple_port(seq_handle, portname, SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,
              SND_SEQ_PORT_TYPE_APPLICATION);
	
	if(res < 0) {
		printf("midi2udp: Error creating MIDI port!\n");
		
		snd_seq_close(seq_handle);
		return false;
	}
	
        res = snd_midi_event_new(MAX_MIDI_MESSAGE_LENGTH, &eventparser);
	if(res != 0) {
		printf("midi2udp: Error making midi event parser!\n");
		
		snd_seq_close(seq_handle);
		return false;
	}
	snd_midi_event_init(eventparser);
	
	midi_event = (snd_seq_event_t*)malloc(sizeof(snd_seq_event_t));
	
	return true;
}
Exemplo n.º 2
0
void stop_midireceiver (JackVST *jvst)
{
	int err; 
	snd_seq_event_t event;
	snd_seq_t *seq2 = create_sequencer ("jfstquit", true);
	
	jvst->midiquit = 1;
	
	snd_seq_connect_to (seq2, 0, snd_seq_client_id (jvst->seq),0);
	snd_seq_ev_clear      (&event);
	snd_seq_ev_set_direct (&event);
	snd_seq_ev_set_subs   (&event);
	snd_seq_ev_set_source (&event, 0);
	snd_seq_ev_set_controller (&event,1,0x80,50);
	
	if ((err = snd_seq_event_output (seq2, &event)) < 0) {
		fst_error ("cannot send stop event to midi thread: %s\n",
			   snd_strerror (err));
	}

	snd_seq_drain_output (seq2);
	snd_seq_close (seq2);
	pthread_join (jvst->midi_thread,NULL);
	snd_seq_close (jvst->seq);
}
Exemplo n.º 3
0
int seq_open() {
  unsigned int caps;
  if (!seq_opened) {
    /* sequencer opening */
    if (snd_seq_open(&seq_handle, "hw", SND_SEQ_OPEN_OUTPUT, 0)) {
      fprintf(stderr, "Error opening ALSA sequencer.\n");
      return(-1);
    }
    /* our client id */
    my_client = snd_seq_client_id(seq_handle);
    /* set client info */
    snd_seq_set_client_name(seq_handle, DEFAULT_NAME);
    /* create port */
    caps = SND_SEQ_PORT_CAP_READ;
    if (seq_client == SND_SEQ_ADDRESS_SUBSCRIBERS)
      caps |= SND_SEQ_PORT_CAP_SUBS_READ;
    my_port = snd_seq_create_simple_port(seq_handle, DEFAULT_NAME, caps,SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION);
    if (my_port < 0) {
      fprintf(stderr, "can't create port\n");
      snd_seq_close(seq_handle);
      return 0;
    }
    /* subscribe to MIDI port */
    if (seq_client != SND_SEQ_ADDRESS_SUBSCRIBERS) {
      if (snd_seq_connect_to(seq_handle, my_port, seq_client, seq_port) < 0) {
        fprintf(stderr, "can't subscribe to MIDI port (%d:%d)\n", seq_client, seq_port);
        snd_seq_close(seq_handle);
        return 0;
      }
    }
  }
  seq_opened = 1;
  return 1;
}
Exemplo n.º 4
0
int ALSAMidiDriver::open() {
	std::string arg;
	unsigned int caps;

	if (isOpen)
		return -1;

	arg = getConfigSetting("alsa_port", ALSA_PORT);

	if (parse_addr(arg, &seq_client, &seq_port) < 0) {
		perr << "ALSAMidiDriver: Invalid port: " << arg << std::endl;
		return -1;
	}
	
	if (my_snd_seq_open(&seq_handle)) {
		perr << "ALSAMidiDriver: Can't open sequencer" << std::endl;
		return -1;
	}

	isOpen = true;
	
	my_client = snd_seq_client_id(seq_handle);
	snd_seq_set_client_name(seq_handle, "PENTAGRAM");
	snd_seq_set_client_group(seq_handle, "input");
	
	caps = SND_SEQ_PORT_CAP_READ;
	if (seq_client == SND_SEQ_ADDRESS_SUBSCRIBERS)
		caps = ~SND_SEQ_PORT_CAP_SUBS_READ;
	my_port =
		snd_seq_create_simple_port(seq_handle, "PENTAGRAM", caps,
								   SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION);
	if (my_port < 0) {
		snd_seq_close(seq_handle);
		isOpen = false;
		perr << "ALSAMidiDriver: Can't create port" << std::endl;
		return -1;
	}

	if (seq_client != SND_SEQ_ADDRESS_SUBSCRIBERS) {
		/* subscribe to MIDI port */
		if (snd_seq_connect_to(seq_handle, my_port, seq_client, seq_port) < 0) {
			snd_seq_close(seq_handle);
			isOpen = false;
			perr << "ALSAMidiDriver: "
				 << "Can't subscribe to MIDI port (" << seq_client
				 << ":" << seq_port << ")" << std::endl;
			return -1;
		}
	}

	pout << "ALSA client initialised [" << seq_client << ":"
		 << seq_port << "]" << std::endl;

	return 0;
}
Exemplo n.º 5
0
static snd_seq_t* createDevice (const bool forInput,
                                const String& deviceNameToOpen)
{
    snd_seq_t* seqHandle = 0;

    if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
                                                      : SND_SEQ_OPEN_OUTPUT, 0) == 0)
    {
        snd_seq_set_client_name (seqHandle,
                                 (const char*) (forInput ? (deviceNameToOpen + T(" Input"))
                                                         : (deviceNameToOpen + T(" Output"))));

        const int portId
            = snd_seq_create_simple_port (seqHandle,
                                          forInput ? "in"
                                                   : "out",
                                          forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
                                                   : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
                                          forInput ? SND_SEQ_PORT_TYPE_APPLICATION
                                                   : SND_SEQ_PORT_TYPE_MIDI_GENERIC);

        if (portId < 0)
        {
            snd_seq_close (seqHandle);
            seqHandle = 0;
        }
    }

    return seqHandle;
}
Exemplo n.º 6
0
static snd_seq_t *create_alsa_seq(const char *client_name,bool isinput){
  snd_seq_t * seq;
  int err;
  
  err = snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0);
  if (err){
    printf( "Could not open ALSA sequencer, aborting\n\n%s\n\n"
	    "Make sure you have configure ALSA properly and that\n"
	    "/proc/asound/seq/clients exists and contains relevant\n"
	    "devices.\n", snd_strerror (err));
    return NULL;
  }
  
  snd_seq_set_client_name (seq, client_name);
  
  err = snd_seq_create_simple_port (seq, isinput==true?"Input":"Output",
                                    (isinput==true?SND_SEQ_PORT_CAP_WRITE:SND_SEQ_PORT_CAP_READ)|SND_SEQ_PORT_CAP_DUPLEX|
                                    SND_SEQ_PORT_CAP_SUBS_READ|SND_SEQ_PORT_CAP_SUBS_WRITE,
                                    SND_SEQ_PORT_TYPE_APPLICATION|SND_SEQ_PORT_TYPE_SPECIFIC);

  if (err){
    printf ( "Could not create ALSA port, aborting\n\n%s\n", snd_strerror (err));
    snd_seq_close(seq);
    return NULL;
  }

  return seq;
}
Exemplo n.º 7
0
void Udp2MidiThread::freeSeq()
{
	int res = snd_seq_close(seq_handle);
	if( res < 0 ) {
		printf("udp2midi: Error closing socket!\n");
	}
}
Exemplo n.º 8
0
void
jack_finish (void *arg)
{
	struct a2j* self = (struct a2j*) arg;
	void* thread_status;

        self->finishing = 1;
        
	a2j_debug("midi: delete");
	
	g_keep_alsa_walking = false;  /* tell alsa io thread to stop, whenever they wake up */
	/* do something that we need to do anyway and will wake the io thread, then join */
	snd_seq_disconnect_from (self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
	a2j_debug ("wait for ALSA io thread\n");
	pthread_join (self->alsa_io_thread, &thread_status);
	a2j_debug ("thread done\n");
	
	jack_ringbuffer_reset (self->port_add);
	
	a2j_stream_detach (&self->stream);
	
	snd_seq_close(self->seq);
	self->seq = NULL;
	
	a2j_stream_close (self);
	
	jack_ringbuffer_free(self->port_add);
	jack_ringbuffer_free(self->port_del);
	
	free (self);
}
Exemplo n.º 9
0
AlsaDevices AlsaMusicPlugin::getAlsaDevices() const {
	AlsaDevices devices;
	snd_seq_t *seq_handle;
	if (my_snd_seq_open(&seq_handle) < 0)
		return devices; // can't open sequencer

	snd_seq_client_info_t *cinfo;
	snd_seq_client_info_alloca(&cinfo);
	snd_seq_port_info_t *pinfo;
	snd_seq_port_info_alloca(&pinfo);
	snd_seq_client_info_set_client(cinfo, -1);
	while (snd_seq_query_next_client(seq_handle, cinfo) >= 0) {
		bool found_valid_port = false;

		/* reset query info */
		snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo));
		snd_seq_port_info_set_port(pinfo, -1);
		while (!found_valid_port && snd_seq_query_next_port(seq_handle, pinfo) >= 0) {
			if (check_permission(pinfo)) {
				found_valid_port = true;

				const char *name = snd_seq_client_info_get_name(cinfo);
				// TODO: Can we figure out the appropriate music type?
				MusicType type = MT_GM;
				int client = snd_seq_client_info_get_client(cinfo);
				devices.push_back(AlsaDevice(name, type, client));
			}
		}
	}
	snd_seq_close(seq_handle);

	return devices;
}
Exemplo n.º 10
0
void MIDIOut::initALSA()
{
	snd_seq_client_info_t* client = NULL;

	/* Destroy the old handle */
	if (m_alsa != NULL)
		snd_seq_close(m_alsa);
	m_alsa = NULL;

	/* Destroy the plugin's own address */
	if (m_address != NULL)
		delete m_address;
	m_address = NULL;

	/* Open the sequencer interface */
	if (snd_seq_open(&m_alsa, "default", SND_SEQ_OPEN_DUPLEX, 0) != 0)
	{
		qWarning() << "Unable to open ALSA interface!";
		m_alsa = NULL;
		return;
	}

	/* Set current client information */
	snd_seq_client_info_alloca(&client);
	snd_seq_set_client_name(m_alsa, name().toAscii());
	snd_seq_get_client_info(m_alsa, client);

	/* Create an application-level port */
	m_address = new snd_seq_addr_t;
	m_address->port = snd_seq_create_simple_port(m_alsa, "__QLC__output",
		   	SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ,
			SND_SEQ_PORT_TYPE_MIDI_GENERIC);
	m_address->client = snd_seq_client_info_get_client(client);
}
Exemplo n.º 11
0
void Midi2UdpThread::freeSeq()
{
	int res = snd_seq_close(seq_handle);
	if( res < 0 ) {
		printf("midi2udp: Error closing socket!\n");
	}
}
Exemplo n.º 12
0
void DeviceManager::loop()
{
    struct pollfd *pfds;
    int npfds;
    int c, err;
    npfds = snd_seq_poll_descriptors_count(handle, POLLIN);
    D("npfds: %d", npfds);
    pfds = (struct pollfd *)alloca(sizeof(*pfds) * npfds);
    for (;;) {
        snd_seq_poll_descriptors(handle, pfds, npfds, POLLIN);
        if (poll(pfds, npfds, -1) < 0)
            break;
        do {
            snd_seq_event_t *event;
            err = snd_seq_event_input(handle, &event);
            if (err < 0)
                break;
            if (event){
                list[0]->processEvent(event);
            }
        } while (err > 0);
        fflush(stdout);
//        if (stop)
//            break;
    }

    snd_seq_close(handle);
}
Exemplo n.º 13
0
/** del_aubio_alsa_seq_driver */
int del_aubio_alsa_seq_driver(aubio_midi_driver_t* p)
{
    aubio_alsa_seq_driver_t* dev;

    dev = (aubio_alsa_seq_driver_t*) p;
    if (dev == NULL) {
        return AUBIO_OK;
    }

    dev->status = AUBIO_MIDI_DONE;

    /* cancel the thread and wait for it before cleaning up */
    if (dev->thread) {
        if (pthread_cancel(dev->thread)) {
            AUBIO_ERR( "Failed to cancel the midi thread");
            return AUBIO_FAIL;
        }
        if (pthread_join(dev->thread, NULL)) {
            AUBIO_ERR( "Failed to join the midi thread");
            return AUBIO_FAIL;
        }
    }
    if (dev->seq_port >= 0) {
        snd_seq_delete_simple_port (dev->seq_handle, dev->seq_port);
    }
    if (dev->seq_handle) {
        snd_seq_drain_output(dev->seq_handle);
        snd_seq_close(dev->seq_handle);
    }
    AUBIO_FREE(dev);
    return AUBIO_OK;
}
Exemplo n.º 14
0
qxgeditMidiDevice::~qxgeditMidiDevice (void)
{
	// Reset pseudo-singleton reference.
	g_pMidiDevice = NULL;

	// Last but not least, delete input thread...
	if (m_pInputThread) {
		// Try to terminate executive thread,
		// but give it a bit of time to cleanup...
		if (m_pInputThread->isRunning()) {
			m_pInputThread->setRunState(false);
		//	m_pInputThread->terminate();
			m_pInputThread->wait();
		}
		delete m_pInputThread;
		m_pInputThread = NULL;
	}

	if (m_pAlsaSeq) {
		snd_seq_delete_simple_port(m_pAlsaSeq, m_iAlsaPort);
		m_iAlsaPort   = -1;
		snd_seq_close(m_pAlsaSeq);
		m_iAlsaClient = -1;
		m_pAlsaSeq    = NULL;
	}
}
Exemplo n.º 15
0
static void
test_teardown (void)
{
  ck_g_object_final_unref (registry);
  if (seq) {
    snd_seq_close (seq);
  }
}
Exemplo n.º 16
0
void JVlibForm::close_seq() {
  if (!seq) return;
  snd_seq_stop_queue(seq,queue,NULL);
  snd_seq_drop_output(seq);
  snd_seq_drain_output(seq);
  snd_seq_close(seq);
  seq = 0;
}
Exemplo n.º 17
0
DeviceManager::~DeviceManager()
{
    snd_seq_close(handle);

    for(std::vector<Device *>::iterator it = list.begin(); it != list.end(); it++){
        delete *it;
    }
    list.clear();
}
Exemplo n.º 18
0
void MidiDriver_ALSA::close() {
	if (_isOpen) {
		_isOpen = false;
		MidiDriver_MPU401::close();
		if (seq_handle)
			snd_seq_close(seq_handle);
	} else
		warning("MidiDriver_ALSA: Closing the driver before opening it");
}
Exemplo n.º 19
0
void free_aseqh(snd_seq_t *handle)
{
  int err = 0;

  err = snd_seq_close(handle);
  if (0 != err)
    output_error("problem while closing alsa seq handler\n%s\n",
                 snd_strerror(err));
}
Exemplo n.º 20
0
MIDIOut::~MIDIOut()
{
	/* Delete all MIDI devices. */
	while (m_devices.isEmpty() == false)
		delete m_devices.takeFirst();

	/* Close the ALSA sequencer interface */
	snd_seq_close(m_alsa);
	m_alsa = NULL;
}
Exemplo n.º 21
0
/** 
 * Get ready to die gracefully.
 */
void
clean_up ( void )
{
	/* release the mouse */
	ioctl( fd, EVIOCGRAB, 0 );

 	close( fd );

	snd_seq_close( seq );
}
Exemplo n.º 22
0
void midi_uninit() {
	if (s_midi == NULL) return;

	snd_midi_event_free(s_midiCoder);
	snd_seq_port_subscribe_free(s_midiSubscription);
	snd_seq_delete_port(s_midi, s_midiPort);
	snd_seq_close(s_midi);

	s_midi = NULL;
}
Exemplo n.º 23
0
/**************************************************************************
 * 			midiCloseSeq				[internal]
 */
static int midiCloseSeq(void)
{
    if (--numOpenMidiSeq == 0) {
	snd_seq_delete_simple_port(midiSeq, port_out);
	snd_seq_delete_simple_port(midiSeq, port_in);
	snd_seq_close(midiSeq);
	midiSeq = NULL;
    }
    return 0;
}
Exemplo n.º 24
0
static PyObject *
alsaseq_close(PyObject *self /* Not used */, PyObject *args)
{
	if (!PyArg_ParseTuple(args, "" ))
		return NULL;

        snd_seq_close(seq_handle);

	Py_INCREF(Py_None);
	return Py_None;
}
Exemplo n.º 25
0
    MidiInputDeviceAlsa::~MidiInputDeviceAlsa() {
        // free the midi ports (we can't let the base class do this,
        // as the MidiInputPortAlsa destructors need access to
        // hAlsaSeq)
        for (std::map<int,MidiInputPort*>::iterator iter = Ports.begin(); iter != Ports.end() ; iter++) {
            delete static_cast<MidiInputPortAlsa*>(iter->second);
        }
        Ports.clear();

        snd_seq_close(hAlsaSeq);
    }
Exemplo n.º 26
0
void AlsaSeqMidiInDriver::close()
{
  if (!this->is_open())
    throw std::logic_error("Device not open");

  if (m_impl->decoder)
    snd_midi_event_free (m_impl->decoder);
  
  snd_seq_close(m_impl->seq);
  m_impl->seq=0;
}
Exemplo n.º 27
0
int bx_sound_linux_c::closemidioutput()
{
#if BX_HAVE_ALSASOUND
  if ((use_alsa_seq) && (alsa_seq.handle != NULL)) {
    snd_seq_close(alsa_seq.handle);
    return BX_SOUNDLOW_OK;
  }
#endif
  fclose(midi);

  return BX_SOUNDLOW_OK;
}
Exemplo n.º 28
0
static void close_handle(snd_seq_t *handle)
{
    int rc;

    rc = snd_seq_close( handle);
    if (rc < 0) {
	g_print( "error closing handle (%s)\n",  snd_strerror(rc));
    }

    return;

} /* close_handle() */
Exemplo n.º 29
0
void sys_alsa_close_midi()
{
    alsa_nmidiin = alsa_nmidiout = 0;
    if(midi_handle)
      {
        snd_seq_close(midi_handle);
        if(midiev)
          {
            snd_midi_event_free(midiev);
          }
      }
}
Exemplo n.º 30
0
static int snd_rawmidi_virtual_close(snd_rawmidi_t *rmidi)
{
	snd_rawmidi_virtual_t *virt = rmidi->private_data;
	virt->open--;
	if (virt->open)
		return 0;
	snd_seq_close(virt->handle);
	if (virt->midi_event)
		snd_midi_event_free(virt->midi_event);
	free(virt);
	return 0;
}