Ejemplo n.º 1
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);
}
Ejemplo n.º 2
0
static PyObject *teardown(PyObject *self, PyObject *args)
{
    if (!PyArg_ParseTuple(args, "")) /* no args */
        return NULL;

    // exit gracefully
    snd_seq_disconnect_to(seq, readable_port, dest_client_id, 0);
    snd_seq_disconnect_from(seq, writable_port, dest_client_id, 0);
    snd_seq_close(seq);

    Py_INCREF(Py_None);
    return Py_None;
}
Ejemplo n.º 3
0
int close_midi_device(struct GenesisMidiDevice *device) {
    if (device->open) {
        if (snd_seq_disconnect_from(device->midi_hardware->seq, 0, device->client_id, device->port_id) < 0)
            return GenesisErrorOpeningMidiHardware;
        device->open = false;
    }
    if (device->set_index >= 0) {
        device->midi_hardware->open_devices.swap_remove(device->set_index);
        if (device->set_index < device->midi_hardware->open_devices.length())
            device->midi_hardware->open_devices.at(device->set_index)->set_index = device->set_index;
        device->set_index = -1;
        genesis_midi_device_unref(device);
    }
    return 0;
}
Ejemplo n.º 4
0
void QMidi::closeMidiOut()
{
#if defined(Q_OS_WIN)
    midiOutClose(midiOutPtr);
#elif defined(Q_OS_LINUX)
    QStringList l = myOutDeviceId.split(":");
    int client = l.at(0).toInt();
    int port = l.at(1).toInt();

    snd_seq_disconnect_from(midiOutPtr, 0, client,port);
#elif defined(Q_OS_HAIKU)
	midiOutLocProd->Disconnect(midiOutConsumer);
	midiOutConsumer->Release();
	midiOutLocProd->Unregister();
	midiOutLocProd->Release();
#endif
}
Ejemplo n.º 5
0
/**************************************************************************
 * 			midClose				[internal]
 */
static DWORD midClose(WORD wDevID)
{
    int		ret = MMSYSERR_NOERROR;

    TRACE("(%04X);\n", wDevID);

    if (wDevID >= MIDM_NumDevs) {
	WARN("wDevID too big (%u) !\n", wDevID);
	return MMSYSERR_BADDEVICEID;
    }
    if (MidiInDev[wDevID].midiDesc.hMidi == 0) {
	WARN("device not opened !\n");
	return MMSYSERR_ERROR;
    }
    if (MidiInDev[wDevID].lpQueueHdr != 0) {
	return MIDIERR_STILLPLAYING;
    }

    if (midiSeq == NULL) {
	WARN("ooops !\n");
	return MMSYSERR_ERROR;
    }
    if (--numStartedMidiIn == 0) {
	TRACE("Stopping thread for midi-in\n");
	end_thread = 1;
	if (WaitForSingleObject(hThread, 5000) != WAIT_OBJECT_0) {
	    WARN("Thread end not signaled, force termination\n");
	    TerminateThread(hThread, 0);
	}
    	TRACE("Stopped thread for midi-in\n");
    }

    snd_seq_disconnect_from(midiSeq, port_in, MidiInDev[wDevID].addr.client, MidiInDev[wDevID].addr.port);
    midiCloseSeq();

    MidiInDev[wDevID].bufsize = 0;
    if (MIDI_NotifyClient(wDevID, MIM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
	WARN("can't notify client !\n");
	ret = MMSYSERR_INVALPARAM;
    }
    MidiInDev[wDevID].midiDesc.hMidi = 0;

    return ret;
}
Ejemplo n.º 6
0
static
int alsa_seqmidi_stop(alsa_midi_t *m)
{
	alsa_seqmidi_t *self = (alsa_seqmidi_t*) m;

	debug_log("midi: stop");

	if (!self->keep_walking)
		return -EALREADY;

	snd_seq_disconnect_from(self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);

	self->keep_walking = 0;

	sem_post(&self->port_sem);
	pthread_join(self->port_thread, NULL);
	self->port_thread = 0;

	return 0;
}
Ejemplo n.º 7
0
int
connect_to_alsa (struct a2j* self)
{
	int error;
	void * thread_status;

	self->port_add = jack_ringbuffer_create(2 * MAX_PORTS * sizeof(snd_seq_addr_t));
	if (self->port_add == NULL) {
		goto free_self;
	}

	self->port_del = jack_ringbuffer_create(2 * MAX_PORTS * sizeof(struct a2j_port *));
	if (self->port_del == NULL) {
		goto free_ringbuffer_add;
	}

	if (!a2j_stream_init(self)) {
		goto free_ringbuffer_outbound;
	}

	if ((error = snd_seq_open(&self->seq, "hw", SND_SEQ_OPEN_DUPLEX, 0)) < 0) {
		a2j_error("failed to open alsa seq");
		goto close_stream;
	}

	if ((error = snd_seq_set_client_name(self->seq, "midi_in")) < 0) {
		a2j_error("snd_seq_set_client_name() failed");
		goto close_seq_client;
	}

	if ((self->port_id = snd_seq_create_simple_port(
		self->seq,
		"port",
		SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_WRITE
#ifndef DEBUG
		|SND_SEQ_PORT_CAP_NO_EXPORT
#endif
		,SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {

		a2j_error("snd_seq_create_simple_port() failed");
		goto close_seq_client;
	}

	if ((self->client_id = snd_seq_client_id(self->seq)) < 0) {
		a2j_error("snd_seq_client_id() failed");
		goto close_seq_client;
	}
	
	if ((self->queue = snd_seq_alloc_queue(self->seq)) < 0) {
		a2j_error("snd_seq_alloc_queue() failed");
		goto close_seq_client;
	}

	snd_seq_start_queue (self->seq, self->queue, 0); 

	a2j_stream_attach (&self->stream);

	if ((error = snd_seq_nonblock(self->seq, 1)) < 0) {
		a2j_error("snd_seq_nonblock() failed");
		goto close_seq_client;
	}

	snd_seq_drop_input (self->seq);

	a2j_add_ports(&self->stream);

	if (sem_init(&self->io_semaphore, 0, 0) < 0) {
		a2j_error("can't create IO semaphore");
		goto close_jack_client;
	}

	g_keep_alsa_walking = true;

	if (pthread_create(&self->alsa_io_thread, NULL, alsa_input_thread, self) < 0)
	{
		a2j_error("cannot start ALSA input thread");
		goto sem_destroy;
	}

	/* wake the poll loop in the alsa input thread so initial ports are fetched */
	if ((error = snd_seq_connect_from (self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE)) < 0) {
		a2j_error("snd_seq_connect_from() failed");
		goto join_io_thread;
	}

	return 0;

	g_keep_alsa_walking = false;  /* tell alsa threads to stop */
	snd_seq_disconnect_from(self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
  join_io_thread:
	pthread_join(self->alsa_io_thread, &thread_status);
  sem_destroy:
	sem_destroy(&self->io_semaphore);
  close_jack_client:
	if ((error = jack_client_close(self->jack_client)) < 0) {
		a2j_error("Cannot close jack client");
	}
  close_seq_client:
	snd_seq_close(self->seq);
  close_stream:
	a2j_stream_close(self);
  free_ringbuffer_outbound:
	jack_ringbuffer_free(self->outbound_events);
	jack_ringbuffer_free(self->port_del);
  free_ringbuffer_add:
	jack_ringbuffer_free(self->port_add);
  free_self:
	free(self);
	return -1;
}